Saturday, 23 April 2016

What are main methods of HttpSession interface ?


The servlet container uses this interface to create a session between an HTTP client and an HTTP server.

The session persists for a specified time period, across more than one connection or page request from the user. A session usually corresponds to one user, who may visit a site many times.

This interface allows Servlets to : 
  • View and manipulate information about a session, such as the session identifier, creation time, and last accessed time
  • Bind objects to sessions, allowing user information to persist across multiple user connections


HttpSession methods

long getCreationTime()
Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.

String getId()
Returns a string containing the unique identifier assigned to this session.

long getLastAccessedTime()
Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT.

void setMaxInactiveInterval(int interval)
int getMaxInactiveInterval()
Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.

void invalidate()
Invalidates this session and unbinds any objects bound to it.

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

void setAttribute(String, Object)
Object getAttribute(String)
Binds an object to this session, using the name specified.

Enumeration getAttributeNames()
Returns an Enumeration of String objects containing the names of all the objects bound to this session.

void removeAttribute(String)

Removes the object bound with the specified name from this session.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.