In the servlet, the session is encapsulated in the Javax.servlet.http.HttpSession interface, which is built on the basis of a cookie or URL rewrite to get an httpsession instance, You can use the HttpServletRequest getsession () method to obtain
HttpServletRequest has two overloaded getsession () methods, one that takes a Boolean type, the other with no arguments, and the GetSession () method and the GetSession (true) method function, That is, if the corresponding client has already generated a session, it will return the old one, otherwise this method will produce a session ID and bind to the corresponding client, if GetSession (false) Indicates that if the corresponding client already has a corresponding session, then the old session is returned, otherwise no new session will be generated. You can use the Isnow () method on the HttpSession object to determine whether this session is a new
HttpSession Common methods
public void setattribute (String name,object value)
Bind a value object to a session with a name name
public Object GetAttribute (String name)
Gets the property value of name and returns NULL if the property does not exist
public void RemoveAttribute (String name)
Removes the Name property from the session and does not throw an error if it does not exist.
Public enumeration Getattributenames ()
Returns the and session-related enumeration values
public void Invalidate ()
Invalidates the session while deleting the Property object
Public Boolean isnew ()
Used to detect whether the current customer is a new session
Public long GetCreationTime ()
return session creation Time
Public long Getlastaccessedtime ()
Returns the time that the Web container received the last request from the customer during session time
public int Getmaxinactiveinterval ()
Returns the maximum time that a customer requests during a session is seconds
public void Setmaxinactiveinterval (int seconds)
Maximum time allowed for customer requests
ServletContext Getservletcontext ()
Returns the context of the current session in which the ServletContext object enables the servlet to communicate with the Web container
Public String getId ()
Returns the identification number during a session
A simple example of saving information to session
Sessionlogin.html