Several ways to set session expiration __java

Source: Internet
Author: User

The default duration of session is 30 minutes, and there are three ways to set session expiration:

1. In the server.xml in Tomcat, define:

The Conf/server.xml file in Tomcat can modify the default validity period for all programs on the server, set the unit to milliseconds, and define the code as follows:

<context path= "/test" docbase= "/test"
defaultsessiontimeout= "36000" iswarexpanded= "true"
Iswarvalidated= "false" isinvokerenabled= "true"
Isworkdirpersistent= "false"/>

2. Defined in the Web.xml of the project:

Modify the expiration date in the engineering Web.xml, set the unit to minutes, and define the code as follows:

<session-config>

<session-timeout>60</session-timeout>

</session-config>

3. Set through Java code:

Set the unit to seconds, set to-1 to mean never expire

Session.setmaxinactiveinterval (30*60)

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.