tags:

views:

2053

answers:

3

Dose anybody know how to set session timeout greater than 30 minutes? these two methods wont work (default to 30 min).

<session-config>
<session-timeout>60</session-timeout>
</session-config>

and

session.setMaxInactiveInterval(600);

Thanks.

A: 

Setting the timeout in the web.xml is the correct way to set the timeout.

Taylor Leese
Yes I know that but it won't let me to set session timeout greater than 30 minutes.
MMRUser
What do you mean "it won't let" you? Does it throw and exception? Prevent the server from starting? Pop up an error dialog? Or just appears to not honor the set timeout?Setting the timeout in the deployment descriptor may require you to restart the web app and/or the server for the new value to take effect. I don't see what would effect calling setMaxInactiveInterval on a session though... maybe something else is setting setMaxInactiveInterval or invalidating the session?
Nate
@Rocky - Same question as Nate. What do you mean by "won't let me"?
Taylor Leese
A: 

if you are allowed to do it globally then you can set the session time out in

TOMCAT_HOME/conf/web.xml as below

 <!-- ==================== 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>60</session-timeout>
</session-config>
shivaspk
I think that sets the default for any web apps that don't supply a value - both setting a default for a specific web app in it's deployment descriptor or calling setMaxInactiveInterval on a specific session should override this.
Nate
+2  A: 

Setting session timeout through the deployment descriptor should work - it sets the default session timeout for the web app. Calling session.setMaxInactiveInterval() sets the timeout for the particular session it is called on, and overrides the default. Be aware of the unit difference, too - the deployment descriptor version uses minutes, and session.setMaxInactiveInterval() uses seconds.

So

<session-config>
    <session-timeout>60</session-timeout>
</session-config>

sets the default session timeout to 60 minutes.

And

session.setMaxInactiveInterval(600);

sets the session timeout to 600 seconds - 10 minutes - for the specific session it's called on.

This should work in Tomcat or Glassfish or any other Java web server - it's part of the spec.

Nate