Javaweb on several setting methods of Session life cycle

Source: Internet
Author: User

The life cycle of the general session is established in the user log on the system after the user information to a record, session similar to you have a bank card, and the money is the memory of the session stored information, card out of the money can not be taken out.

The lifetime of the previous session was that the client did not interact with the server within 20 minutes and the session was destroyed; some servers now have a lifetime of 30 minutes. Session sessions are stored on the server side.

Here are the settings for several life cycles of the session:

One, the most brutal way to set up

Modify the value in <session-time-out></session-time-out> in the Web. xml file under the server's corresponding configuration file.

As shown in the following:

Tomcat default session timeout is 30 minutes, can be modified as needed, negative or 0 is not limit session failure time.

Second, commonly used is also a relatively simple method

Configure parameters in your project's Web. xml file:

The corresponding XML code is as follows:

<session-config>
<session-timeout>20</session-timeout>
</session-config>

The above 20 means that the duration of the session is 20 minutes. This is calculated in minutes.

Three, a more docile way of setting up

Add the following code in the main Page/public page/or in the code below the corresponding servlet:

Session.setmaxinactiveinterval (You want to set the time);

The time that is set is calculated in seconds, and it is calculated based on the server.

Note: The above priority is: three-two > A

Javaweb on several setting methods of Session life cycle

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.