File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Default session timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Default session timeout" Watch "Default session timeout" New topic

Default session timeout

Haris Karameh
Ranch Hand

Joined: Oct 17, 2002
Posts: 38
Is there an easy way to get a default httpsession timeout value inside init().
As begginer I have a several ideas how to do it but they are not simple.
TIA Haris
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
inside of init() in a servlet?

The easiest way would be to define an init parameter for your servlet in the web.xml:

You would maintain this value to be the same value as the default session timeout (later on in web.xml):
<!-- the time in minutes -->

Then your servlet would read the value of the its init parameter:
public void init(ServletConfig config)
throws ServletException {
int defaultTimeout = 60; // our default we use when no init parameter;
try {
defaultTimeout = Integer.parseInt(config.getInitParameter("defaultSessionTimeout");
} catch (NumberFormatException ex) { /* empty */ }

// other init related stuff

Error: Keyboard not attached. Press F1 to continue.
I agree. Here's the link:
subject: Default session timeout
jQuery in Action, 3rd edition