JSP/JSTL Session Timeout Detection

Posted on 2009-12-30
Last Modified: 2013-12-02
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.
Question by:lcor
    LVL 3

    Assisted Solution

    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!!
    LVL 40

    Accepted Solution

    just check
    HttpSession session = request.getSession();

    if (session == null)
       \\TODO: session has timed out.
    LVL 20

    Expert Comment

    by:Sathish David Kumar N
    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 !!
    LVL 20

    Assisted Solution

    by:Sathish David Kumar N
    if(request.getSession(false) == null)
     // redirect to login page

    if((String)request.getSession(false).getAttribute("user")== null)
     // redirect to login page

    Author Closing Comment

    used the last 2 solutions, but the struts solution was good to know

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now