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

Package freemarker.ext.jakarta.servlet

# Class HttpSessionHashModel

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

All Implemented Interfaces:
  `TemplateHashModel`, `TemplateModel`, `Serializable`

public final class HttpSessionHashModel extends Object implements TemplateHashModel, Serializable
TemplateHashModel wrapper for a HttpSession 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!

See Also:
  Serialized Form

- ## Field Summary

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

  `NOTHING`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HttpSessionHashModel​(FreemarkerServlet servlet, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, ObjectWrapper wrapper)`
  Use this constructor when the session isn't already created.
  `HttpSessionHashModel​(jakarta.servlet.http.HttpSession session, ObjectWrapper wrapper)`
  Use this constructor when the session already exists.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TemplateModel`
  `get​(String key)`
  Gets a `TemplateModel` from the hash.
  `boolean`
  `isEmpty()`

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

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

- ## Constructor Details

  - ### HttpSessionHashModel

    public HttpSessionHashModel​(jakarta.servlet.http.HttpSession session, ObjectWrapper wrapper)
    Use this constructor when the session already exists.
    Parameters:
      `session` - the session
      `wrapper` - an object wrapper used to wrap session attributes

  - ### HttpSessionHashModel

    public HttpSessionHashModel​(FreemarkerServlet servlet, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, ObjectWrapper wrapper)
    Use this constructor when the session isn't already created. It is passed enough parameters so that the session can be properly initialized after it's detected that it was created.
    Parameters:
      `servlet` - the FreemarkerServlet that created this model. If the model is not created through FreemarkerServlet, leave this argument as null.
      `request` - the actual request
      `response` - the actual response
      `wrapper` - an object wrapper used to wrap session attributes

- ## 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() throws TemplateModelException
    Specified by:
      `isEmpty` in interface `TemplateHashModel`
    Throws:
      `TemplateModelException`