This article describes the Java set session expiration time to achieve the method to share for everyone to reference. The implementation methods are as follows:
1, Timeout in the deployment descriptor (Web.xml)
In minutes
Copy Code code as follows:
<web-app ...>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
This setting takes effect for the entire Web application. When the client does not initiate a request within 20 minutes, the container kills the session.
2. Timeout with Setmaxinactiveinterval ()
Specifies, in seconds, the expiration time of a specific session by encoding. For example:
Copy Code code as follows:
HttpSession session = Request.getsession ();
Session.setmaxinactiveinterval (20*60);
The above setting is only in session which called "Setmaxinactiveinterval ()" method, and session would be kill by C Ontainer if client doesn ' t make no request after minutes.
Thoughts .....
This is a bit confusing, the value in Deployment Descriptor (Web.xml) are in "minute", but the Setmaxinactiveinterval () Me Thod is accept the ' value in ' second '. Both functions should synchronize it in future release
3, defined in the program, the unit is seconds, set to-1 means never expire, sample code is:
Copy Code code as follows:
Session.setmaxinactiveinterval (30*60);
Session settings have the effect of priority is, first after the program configuration, first local after the whole.
I hope this article will help you with your Java programming.