• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1701
  • Last Modified:

JSP/JSTL Session Timeout Detection

I have a JSP/JSTL application.  Session timeout is set to 30 mins in Apache/Tomcat configuration file.  

Is there a way within the application to detect the session has timed out?  This way, if the application sits and the user hits the web application, I can display a message "Session has timed out.  Refresh report" Alot of the data displayed is at session level.
3 Solutions
You can do this by simply adding a controller. Each time user requests server, this class will be triggered. So you can use this class to validate the users session.

1) Define your controller in a config file..

If you using Struts framework, then you can add a similar line in your struts-config.xml
<controller processorClass="com.myDomain.myNameSpace.myController" />

2) Then define a class myController and look for a specific object in session scope... preferably user profile, where you will store user name and other information

If the object exists, then session is still valid, so continue with the users request

if the object doesnot exist, then redirect to a page which says "session timeout"

Let me know if it helps!!
Gurvinder Pal SinghCommented:
just check
HttpSession session = request.getSession();

if (session == null)
   \\TODO: session has timed out.
Sathish David Kumar NCommented:
With out any action u cant find the session timeout !!

I think u define the timeout with redriect to LoginPage ..

when ever any action happend then if thats session timeout means it will go to the Login page !!
Sathish David Kumar NCommented:
if(request.getSession(false) == null)
 // redirect to login page

if((String)request.getSession(false).getAttribute("user")== null)
 // redirect to login page
lcorAuthor Commented:
used the last 2 solutions, but the struts solution was good to know

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now