aspose file tools*
The moose likes Servlets and the fly likes Servlet Timeout in two ways Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Timeout in two ways" Watch "Servlet Timeout in two ways" New topic
Author

Servlet Timeout in two ways

Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
Hi All,

There are two ways of setting session time-out for servlet. one is giving in web.xml and another is setting the Inactive interval by calling setMaxInactiveInterval on HttpSession.

What are the conceptual differences between these two ways?

Regards,
Anant
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39572
    
  27
There is no conceptual difference, as both settings affect the same parameter. The one in web.xml is used if setMaxInactiveInterval is not called.
[ March 15, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Be careful that the parameter for setMaxInactiveInterval is expressed in seconds, whereas the one in the deployment descriptor is in minutes.


[My Blog]
All roads lead to JavaRanch
Sunil Vasudevan
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
There is one more difference.

When we configure session timeout in web.xml, it is applicable to all the sessions created.

When we call setMaxInactiveInterval(int interval) on a session object, then the timeout is set only for that specific session object.

If you have specified a timeout value in web.xml and also calling setMaxInactiveInterval(int interval) on a session object, then for that session object, value set in setMaxInactiveInterval() will be considered for timeout.


Sunil.V<br />SCJP2, SCWCD1.4, SCBCD1.3
Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
thanks all. i understood the difference..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlet Timeout in two ways
 
Similar Threads
forwarding xml cotent from servlet to a jsp
How to Get a String attribute from Request Using EL?
Setting HttpOnly and Secure attributes in Struts2
Servlet Calling?
Relation between char-set and encoding