3 ways to set the session validity period

1. As far as I know, there are currently 3 ways to set the session validity period:

A. Use the java function: session.setMaxInactiveInterval()

  1.  Example: session.setMaxInactiveInterval(30 * 60); The unit is second (s), the validity period of this setting is 30min
  2.   Note: If you set a value of zero or negative, it means the session will never time out!

B. Configure in session-config in project web.xml

  1. Example: Set the validity period to 30 minutes
  2. <session-config>
  3. <session-timeout>30</session-timeout>
  4. </session-config>

Note: In minutes, it must be an integer. If the value of the session-timeout element is zero or negative, it means that the session will never time out!

C. Set directly in the application server (for example, tomcat)

  1. You can find the <session-config> element in conf/web.xml in the tomcat directory. The default setting of tomcat is 30 minutes.
  2. Note: In minutes, it must be an integer. If the value of the session-timeout element is zero or negative, it means that the session will never time out!

2. These three methods set the priority of the session validity period (here the priority refers to the priority if the three methods A, B, and C are used at the same time)

       A>B>C

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324517400&siteId=291194637