I want my servlet page to redirect to a login page if the session has timed out. How can I know if my session has timed out?

Dieter Wimberger

If the servlet engine does the time-out, following code should help you:

//assume you have a HttpServletRequest request
if(request.getSession(false)==null) {
  //no valid session (timeouted=invalid)
  //code to redirect to login page
[See also Servlets API Specification 2.2]
Note that the code should work under 2.0 and 2.1 as well.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact