For the contents of the Session, refer to the http-session mechanism
Create and retrieve HttpSession
The HttpSession instance can be obtained through the Httpservletrequest.getsession method. The HttpServletRequest has two overloaded getsession methods:
Public HttpSession getsession (); Public HttpSession getsession (boolean create);
The parameterless GetSession method returns the current HttpSession instance object and creates a new HttpSession instance if the HttpSession instance does not currently exist. If the HttpSession instance does not currently exist, the GetSession (false) method does not create a new HttpSession instance, and GetSession (true) is the same as getsession ().
Setting and Getting properties
The SetAttribute method can set property values on an HttpSession instance. The HttpSession property value can be not only a String type, but also a type that implements the java.io.Serializable arbitrarily. This allows the Servlet container to serialize the session to a file or database when the server is running out of memory. If the HttpSession property value is not serializable, an exception is thrown when the Servlet container attempts to serialize the session.
The GetAttribute method can get the property value of the HttpSession instance, and the Getattributenames method is to get the name of all the properties of the HttpSession instance.
Other methods
GetId: Returns a String that contains the unique identifier assigned to this session. Identifiers are assigned by the Servlet container and are implementation-dependent.
GetCreationTime: Returns the time that this session was created.
Getlastaccessedtime: Returns the time at which the client last sent a request associated with this session.
Getmaxinactiveinterval: Returns the idle time, in seconds, for this session.
Setmaxinactiveinterval: Sets the idle time, in seconds, for this session.
Invalidate: Invalidates this session, and then cancels the binding to any object bound to it.
IsNew: Determines whether this session is new.
Servlets & Jsp-httpsession