I have a requirement to set the session timeout of 40 seconds. I know we keep normally to 20 minutes.
But my current application requirement is to keep the session timeout to 40 seconds. The web.xml is taking only integer value as 1 but it is not taking 0.6. Is there any way to write this? We are running our java web application on Apache tomcat server.
So how do I set session timeout in seconds in web.xml?
Using the deployment descriptor, you can only set the timeout 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 a servlet container:
HttpSession session = request.getSession();
session.setMaxInactiveInterval(40);
Suggested reading: Deployment Descriptor Elements
well in web.xml file you can provide in minutes
<session-config>
<session-timeout>Minutes</session-timeout>
</session-config>
but you programatically provide values in seconds
HttpSession session = request.getSession();
session.setMaxInactiveInterval(20*60);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With