• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Default session timeout

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic