Three methods for setting session timeout (invalidation) in Java

  • 2020-04-01 03:58:43
  • OfStack

1. Set up in the web container (tomcat here)
Set in tomcat-5.0.28\conf\web.xml, the following is the default configuration in tomcat 5.0:


<!-- ==================== Default Session Configuration ================= --> 
  <!-- You can set the default session timeout (in minutes) for all newly   --> 
  <!-- created sessions by modifying the value below.    --> 
    <session-config> 
        <session-timeout>30</session-timeout> 
</session-config> 

Tomcat's default session timeout is 30 minutes, which can be modified as needed. Negative Numbers or 0 do not limit session expiration time.
2.     Set in the web.xml of the project

<!-- Time is measured in minutes    -->
[html] view plaincopy
<session-config> 
      <session-timeout>15</session-timeout> 
</session-config> 

3.   Set through Java code

session.setMaxInactiveInterval ( 30*60 ) ;//In seconds & NBSP; < br / >


Related articles: