Package spark

Class Session


  • public class Session
    extends java.lang.Object
    Provides session information.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Request request  
      private javax.servlet.http.HttpSession session  
    • Constructor Summary

      Constructors 
      Constructor Description
      Session​(javax.servlet.http.HttpSession session, Request request)
      Creates a session with the HttpSession.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T attribute​(java.lang.String name)
      Returns the object bound with the specified name in this session, or null if no object is bound under the name.
      void attribute​(java.lang.String name, java.lang.Object value)
      Binds an object to this session, using the name specified.
      java.util.Set<java.lang.String> attributes()  
      long creationTime()  
      java.lang.String id()  
      void invalidate()
      Invalidates this session then unbinds any objects bound to it.
      boolean isNew()  
      long lastAccessedTime()  
      int maxInactiveInterval()  
      void maxInactiveInterval​(int interval)
      Specifies the time, in seconds, between client requests the web container will invalidate this session.
      javax.servlet.http.HttpSession raw()  
      void removeAttribute​(java.lang.String name)
      Removes the object bound with the specified name from this session.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • request

        private final Request request
      • session

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

      • Session

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

      • raw

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

        public <T> T attribute​(java.lang.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​(java.lang.String name,
                              java.lang.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 java.util.Set<java.lang.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 java.lang.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​(java.lang.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