HttpSession Interface

public interface HttpSession
This interface from the javax.servlet.http package encapuslates the notion of a session. An object of this type can be obtained usting the getSession() method of the HttpServletRequest object.
Since sessions are maintained on the server side, and since HTTP is a stateless protocol, the web container cannot determine if the client intends to continue to use the web application.
Method of HttpSession Interface
  1. public Object getAttribute(String name)
              This method returns the object bound with the specified name in this session, or null if no object is bound under the name.  
  2. public Enumeration getAttributeNames()
              This method returns an Enumeration of String objects containing the names of all the objects bound to this session.
  3. public long getCreationTime()
              This method returns the time when this session was created, measured in milliseconds since midnight March 27, 2013 00:00:00 GMT.
  4. public String getId()
              This method returns a string containing the unique identifier assigned to this session.
  5. public long getLastAccessedTime()
              This method returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT.
  6. public  int getMaxInactiveInterval()
              This method returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.
  7. public HttpSessionContext getSessionContext()
              Deprecated. As of Version 2.1, this method is deprecated and has no replacement. It will be removed in a future version of the Java Servlet API.  Object getValue(String name)
              Deprecated. As of Version 2.2, this method is replaced by getAttribute(String).
  8. public  String[] getValueNames()
              Deprecated. As of Version 2.2, this method is replaced by getAttributeNames()  void invalidate()
              Invalidates this session and unbinds any objects bound to it.
  9. public  boolean isNew()
              This method returns true if the client does not yet know about the session or if the client chooses not to join the session.
  10. public void putValue(String name, Object value)
              Deprecated. As of Version 2.2, this method is replaced by setAttribute(String, Object)  
  11. public void removeAttribute(String name)
              This method removes the object bound with the specified name from this session.  
  12. public void removeValue(String name)
              Deprecated. As of Version 2.2, this method is replaced by setAttribute(String, Object)  
  13. public void setAttribute(String name, Object value)
              This method binds an object to this session, using the name specified.
  14. public void setMaxInactiveInterval(int interval)
              This method specifies the time, in seconds, between client requests before the servlet container will invalidate this session.


Latest Tutorial

Most Visited Tutorial