JavaScript is disabled on your browser.
  • Summary:
  • Nested |
  • Field |
  • Constr |
  • Method
  • Detail:
  • Field |
  • Constr |
  • Method
javax.servlet.http

Interface HttpSession



  • public interface HttpSession
    A HttpSession holds session-dependant data on the server side. A servlet can request the servlet by using HttpServletRequest.getSession(...)

    The handling of the Session objects is a job done by the server and servlets together.

    As follows:
    The server maintains the set of HttpSessions.
    The server creates HttpSession on request by a servlet
    The server removes all invalidated HttpSessions
    The server connects an incoming request with its HttpSession (usually done using cookies)
    Servlets manipulate the contents of the HttpSession by adding and removing items.
    Servlets ask the server to remove HttpSessions by invalidating them
    Since:
    2.0
    • Method Summary

      Methods
      Modifier and Type Method and Description
      java.lang.Object getAttribute (java.lang.String name)
      get the attribute value associated with the name
      java.util.Enumeration getAttributeNames ()
      get the list of attribute names
      long getCreationTime ()
      Gets this session's creation time in seconds since january 1st 1970.
      java.lang.String getId ()
      Gets the unique session id.
      long getLastAccessedTime ()
      Gets the number of seconds since the previous access of this session.
      int getMaxInactiveInterval ()
      Returns the minimum time this session will be kept alive by the server when it doesn't get accessed by a client.
      ServletContext getServletContext ()
      Get the ServletContext to which this session belongs
      HttpSessionContext getSessionContext ()
      Deprecated.
      HttpSessionContext has been deprecated for security reasons.
      java.lang.Object getValue (java.lang.String name)
      Deprecated.
      java.lang.String[] getValueNames ()
      Deprecated.
      void invalidate ()
      Make this HttpSession unavailable for use by other servlets and tell the server to remove this session.
      boolean isNew ()
      Returns whether this session has been freshly created.
      void putValue (java.lang.String name, java.lang.Object value)
      Deprecated.
      Servlet API 2.2 use instead
      void removeAttribute (java.lang.String name)
      remove the specified attribute.
      void removeValue (java.lang.String name)
      Deprecated.
      void setAttribute (java.lang.String name, java.lang.Object value)
      set the attribute value to be associated with the name.
      void setMaxInactiveInterval (int interval)
      Sets the minimum time this session will be kept alive by the server when it doesn't get accessed by a client.
      Note: hmmm, should an interval of -1 mean that it should live forever?
    • Method Detail

      • getCreationTime

        long getCreationTime()
        Gets this session's creation time in seconds since january 1st 1970.
        Returns:
        a number of seconds
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
      • getId

        java.lang.String getId()
        Gets the unique session id. Every HttpSession has a Id that is unique for this (virtual) http server.
        Returns:
        The Id
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
      • getLastAccessedTime

        long getLastAccessedTime()
        Gets the number of seconds since the previous access of this session. Every time a client's request comes in the server checks (usually by using cookies) which HttpSession object corresponds with this particular client. The server then sets the lastAccessedTime to the current time. (And the isNew flag to false.) If the client has never requested anything with this Session then this method returns -1
        Returns:
        number of seconds since last access or -1
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
      • getServletContext

        ServletContext getServletContext()
        Get the ServletContext to which this session belongs
        Returns:
        the ServletContext representing the web application of which this session is a part.
        Since:
        2.3
      • setMaxInactiveInterval

        void setMaxInactiveInterval(int interval)
        Sets the minimum time this session will be kept alive by the server when it doesn't get accessed by a client.
        Note: hmmm, should an interval of -1 mean that it should live forever?
        Parameters:
        interval - Probably seconds or -1 if never
        Throws:
        java.lang.IllegalStateException - if this session has been invalidated
        Since:
        2.1
      • getMaxInactiveInterval

        int getMaxInactiveInterval()
        Returns the minimum time this session will be kept alive by the server when it doesn't get accessed by a client.
        Since:
        2.1
      • getSessionContext

        HttpSessionContext getSessionContext()
        Deprecated. HttpSessionContext has been deprecated for security reasons.
        Gets this HttpSession's context. The context contains information that is the same for all HttpSessions for this (virtual) host.
        Returns:
        The context
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
      • getAttribute

        java.lang.Object getAttribute(java.lang.String name)
        get the attribute value associated with the name
        Parameters:
        name - the name of the attribute
        Returns:
        the Object associated with this name
        Throws:
        java.lang.IllegalStateException - if this session has been invalidated
        Since:
        2.2
      • getValue

        java.lang.Object getValue(java.lang.String name)
        Deprecated. use getAttribute(java.lang.String) instead
        Gets a object from the set of name/value pairs in the session.
        Parameters:
        name - the name of the item required
        Returns:
        the value of the item. null if not present.
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
      • getAttributeNames

        java.util.Enumeration getAttributeNames()
        get the list of attribute names
        Throws:
        java.lang.IllegalStateException - if this session has been invalidated
        Since:
        2.2
      • getValueNames

        java.lang.String[] getValueNames()
        Deprecated. use getAttributeNames() instead
        Get a list of all item names in the session.
        Returns:
        An array of Strings containing all item names.
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
      • setAttribute

        void setAttribute(java.lang.String name,
         java.lang.Object value)
        set the attribute value to be associated with the name.
        Throws:
        java.lang.IllegalStateException - if this session has been invalidated
        Since:
        2.2
      • putValue

        void putValue(java.lang.String name,
         java.lang.Object value)
        Deprecated. Servlet API 2.2 use instead
        Puts a name and value in the HttpSession. If the Object implements HttpSessionBindindListener then the valueBound() method of the Object will be called.
        Parameters:
        name - the name of the item
        value - the value of the item
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
      • removeAttribute

        void removeAttribute(java.lang.String name)
        remove the specified attribute.
        Throws:
        java.lang.IllegalStateException - if this session has been invalidated
        Since:
        2.2
      • removeValue

        void removeValue(java.lang.String name)
        Deprecated. use removeAttribute(java.lang.String) instead
        Removes an item from the session. If the Object implements HttpSessionBindindListener then the valueUnBound() method of the Object will be called.
        Parameters:
        name - the name of the item.
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
      • invalidate

        void invalidate()
        Make this HttpSession unavailable for use by other servlets and tell the server to remove this session. All values bound to this session with putValue() that implement HttpSessionBindingListener will be called with valueUnbound(). Also: make it throw an IllegalStateException when a servlet tries to execute one of its methods.
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
      • isNew

        boolean isNew()
        Returns whether this session has been freshly created. A servlet can ask the server to give the HttpSession connected with this request/client. The Servlet can use this method to check whether the HttpSession has been newly created or if a HttpSession had already been created for a previous request.
        Returns:
        Whether this is a new HttpSession
        Throws:
        java.lang.IllegalStateException - if the session has been invalidated.
  • Summary:
  • Nested |
  • Field |
  • Constr |
  • Method
  • Detail:
  • Field |
  • Constr |
  • Method

AltStyle によって変換されたページ (->オリジナル) /