ServletContextHashModel (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.ext.jakarta.servlet, class: ServletContextHashModel

Package freemarker.ext.jakarta.servlet

# Class ServletContextHashModel

java.lang.Object
freemarker.ext.jakarta.servlet.ServletContextHashModel

All Implemented Interfaces:
  `TemplateHashModel`, `TemplateModel`

public final class ServletContextHashModel extends Object implements TemplateHashModel
TemplateHashModel wrapper for a ServletContext attributes.

Note that there are two variants of this class: One for the legacy "javax" Servlet API in the `freemarker.ext``.servlet` package, and another for the newer Jakarta Servlet API in the `freemarker.ext``.jakarta.servlet` package (since 2.3.33). Use the variant that fits your Servlet container!

- ## Field Summary

  ### Fields inherited from interface freemarker.template.TemplateModel

  `NOTHING`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ServletContextHashModel​(jakarta.servlet.GenericServlet servlet, ObjectWrapper wrapper)`
  `ServletContextHashModel​(jakarta.servlet.ServletContext servletctx, ObjectWrapper wrapper)`
  Deprecated.
  use `ServletContextHashModel(GenericServlet, ObjectWrapper)` instead.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TemplateModel`
  `get​(String key)`
  Gets a `TemplateModel` from the hash.
  `jakarta.servlet.GenericServlet`
  `getServlet()`
  Returns the underlying servlet.
  `boolean`
  `isEmpty()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ServletContextHashModel

    public ServletContextHashModel​(jakarta.servlet.GenericServlet servlet, ObjectWrapper wrapper)

  - ### ServletContextHashModel

    @Deprecated public ServletContextHashModel​(jakarta.servlet.ServletContext servletctx, ObjectWrapper wrapper)
    Deprecated.
    use `ServletContextHashModel(GenericServlet, ObjectWrapper)` instead.

- ## Method Details

  - ### get

    public TemplateModel get​(String key) throws TemplateModelException
    Description copied from interface: `TemplateHashModel`
    Gets a `TemplateModel` from the hash.
    Specified by:
      `get` in interface `TemplateHashModel`
    Parameters:
      `key` - The name by which the `TemplateModel` is identified in the template.
    Returns:
      The `TemplateModel` referred to by the key, or `null` if not found.
    Throws:
      `TemplateModelException`

  - ### isEmpty

    public boolean isEmpty()
    Specified by:
      `isEmpty` in interface `TemplateHashModel`

  - ### getServlet

    public jakarta.servlet.GenericServlet getServlet()
    Returns the underlying servlet. Can return null if this object was created using the deprecated constructor.