Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set session timeout in seconds in web.xml?

Tags:

java

tomcat

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?

like image 616
user3488632 Avatar asked Apr 11 '14 06:04

user3488632


2 Answers

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

like image 106
Juned Ahsan Avatar answered Oct 22 '22 15:10

Juned Ahsan


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);
like image 3
Sanjay Rabari Avatar answered Oct 22 '22 13:10

Sanjay Rabari