Package spark

Class Session

java.lang.Object
spark.Session

public class Session extends Object
Provides session information.
  • Field Details

    • request

      private final Request request
    • session

      private final javax.servlet.http.HttpSession session
  • Constructor Details

    • Session

      Session(javax.servlet.http.HttpSession session, Request request)
      Creates a session with the HttpSession.
      Parameters:
      session -
      request -
      Throws:
      IllegalArgumentException - If the session or the request is null.
  • Method Details

    • raw

      public javax.servlet.http.HttpSession raw()
      Returns:
      the raw HttpSession object handed in by the servlet container.
    • attribute

      public <T> T attribute(String name)
      Returns the object bound with the specified name in this session, or null if no object is bound under the name.
      Type Parameters:
      T - The type parameter
      Parameters:
      name - a string specifying the name of the object
      Returns:
      the object with the specified name
    • attribute

      public void attribute(String name, Object value)
      Binds an object to this session, using the name specified.
      Parameters:
      name - the name to which the object is bound; cannot be null
      value - the object to be bound
    • attributes

      public Set<String> attributes()
      Returns:
      an Enumeration of String objects containing the names of all the objects bound to this session.
    • creationTime

      public long creationTime()
      Returns:
      the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
    • id

      public String id()
      Returns:
      a string containing the unique identifier assigned to this session.
    • lastAccessedTime

      public long lastAccessedTime()
      Returns:
      the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT, and marked by the time the container received the request.
    • maxInactiveInterval

      public int maxInactiveInterval()
      Returns:
      the maximum time interval, in seconds, that the container will keep this session open between client accesses.
    • maxInactiveInterval

      public void maxInactiveInterval(int interval)
      Specifies the time, in seconds, between client requests the web container will invalidate this session.
      Parameters:
      interval - the interval
    • invalidate

      public void invalidate()
      Invalidates this session then unbinds any objects bound to it.
    • isNew

      public boolean isNew()
      Returns:
      true if the client does not yet know about the session or if the client chooses not to join the session.
    • removeAttribute

      public void removeAttribute(String name)
      Removes the object bound with the specified name from this session.
      Parameters:
      name - the name of the object to remove from this session