How to set session timeout in seconds in web.xml?

I have a requirement to set the session timeout to 40 seconds. I know that we continue normally until 20 minutes. But my current application requirement is to keep the session timeout up to 40 seconds. Web.xml accepts only an integer value as 1, but does not accept 0.6. Is there any way to write this? We run our Java application on the Apache Tomcat server.

So how to set session timeout in seconds in web.xml?

+8
source share
4 answers

Using the deployment descriptor , you can set the timeout only in minutes :

<session-config> <session-timeout>1</session-timeout> </session-config> 


But using the HttpSession API you can set the session timeout in seconds for the servlet container:

 HttpSession session = request.getSession(); session.setMaxInactiveInterval(40); 

Recommended Reading: Deployment Descriptor Elements

+14
source

well in the web.xml file that you can provide in minutes

 <session-config> <session-timeout>Minutes</session-timeout> </session-config> 

but you programmatically provide values ​​in seconds

 HttpSession session = request.getSession(); session.setMaxInactiveInterval(20*60); 
+3
source
 1) Timeout in the deployment descriptor (web.xml) 

- sets the timeout value to "minute", encloses the "session-config" element.

Markup

 <web-app ...> <session-config> <session-timeout>20</session-timeout> </session-config> </web-app> 

The above parameter applies to the entire web application, and the session will be killed by the container if the client does not make a request after 20 minutes.

 2) Timeout with setMaxInactiveInterval() 

- You can manually specify the timeout value in seconds for a specific session.

Java

 HttpSession session = request.getSession(); session.setMaxInactiveInterval(20*60); 

The above parameter applies only to the session that calls the setMaxInactiveInterval () method, and the session will be killed by the container if the client does not complete any request after 20 minutes.

0
source

you can override the session timeout through "setMaxInactiveInterval ()".

 HttpSession session = request.getSession(); session.setMaxInactiveInterval(20000); 

here it will take time in milliseconds, which means that the session will expire in the next 20 seconds.

0
source

All Articles