inside of init() in a
servlet?
The easiest way would be to define an init parameter for your servlet in the web.xml:
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>package.to.MyServlet</servlet-class>
<init-param>
<param-name>defaultSessionTimeout</param-name>
<param-value>60</param-value>
</init-param>
</servlet>
You would maintain this value to be the same value as the default session timeout (later on in web.xml):
<session-config>
<!-- the time in minutes -->
<session-timeout>60</session-timeout>
</session-config>
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
}