Java settings How to configure the session expiration time

Source: Internet
Author: User

1) Timeout in the deployment descriptor (Web. xml)
In minutes

Code to copy code as follows
<web-app ...>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>

The above 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 the expiration time, in seconds, for a specific session by encoding. For example:

Code to copy code as follows
HttpSession session = Request.getsession ();
Session.setmaxinactiveinterval (20*60);

The above setting is only apply on session which call the "Setm (www.111cn.net) Axinactiveinterval ()" method, and session WI ll be kill by container if client doesn ' t do any request after minutes.

Thoughts ....
This was a bit confusing, the value in Deployment Descriptor (Web. xml) is in "minute", but the Setmaxinactiveinterval () Me Thod is to accept the value in "second". Both functions should synchronize it in the future release

3) defined in the program, in seconds, set to 1 means never expires, the sample code is:

Code to copy code as follows
Session.setmaxinactiveinterval (30*60);

The priority of the session setting effect is, the first program after the configuration, the first local after the whole
From:http://www.111cn.net/jsp/java/59186.htm

Java settings How to configure the session expiration time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.