Switch
Switch

Reputation: 15453

How do I set session timeout of greater than 30 minutes

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.

Upvotes: 14

Views: 112541

Answers (5)

UdayKiran Pulipati
UdayKiran Pulipati

Reputation: 6667

If you want to never expire a session use 0 or negative value -1.

<session-config>
    <session-timeout>0</session-timeout>
</session-config>

or mention 1440 it indicates 1440 minutes [24hours * 60 minutes]

<session-config>
  <session-timeout>1440</session-timeout><!-- 24hours -->
</session-config>

Session will be expire after 24hours.

Upvotes: 10

Elye M.
Elye M.

Reputation: 2737

this will set your session to keep everything till the browser is closed

session.setMaxinactiveinterval(-1);

and this should set it for 1 day

session.setMaxInactiveInterval(60*60*24);

Upvotes: 2

Nate
Nate

Reputation: 16898

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.

Upvotes: 12

shivaspk
shivaspk

Reputation: 610

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>

Upvotes: 1

Taylor Leese
Taylor Leese

Reputation: 52310

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

Upvotes: 0

Related Questions