Reset login indicator after session timeout.

Posted on 2007-08-02
Last Modified: 2013-12-11

I have a Java/STRUTS application running on Websphere Application Server 6.0 with a DB2 database. I need to set the session timeout on the WAS to 480mins (users request).

I'd like to know how i can reset a field in the DB2 table from 1 to 0 when a session timeout occurs. The reason for this is when the user attempts to logon after the session timeout the field is still set to 1 and will inform the user that they are already logged in!! Of course when the user logs off correctly the field is reset to 0.

Thanks in advance.
Question by:ssheikh7
    LVL 17

    Expert Comment

    i think you wont be able to trigger an action for timeout. so the best way of doing this is implement a pice of code yourself to take care of this session timeout and change the vale in the db. simple html page given below which uses javascript to handle this

    <script language=javascript>

    var secondsLeft;                                    // seconds left before timeout
    var sampleFrequency = 1;                        // frequency to peek at time left
    var interval = null;                              // timer
    var minutesleftWarning = 2;                        // when to warn user (in minutes)
    var hasBeenWarned = false;
    function InitTimeoutCountdown()
          secondsLeft = 125;
          hasBeenWarned = false;
          interval = setInterval("CheckForSessionTimeout()",sampleFrequency*1000);
    function CheckForSessionTimeout()
          secondsLeft = secondsLeft - sampleFrequency;
                      document.mainform.tbox.value = secondsLeft;
          if (secondsLeft < minutesleftWarning * 60)
                if (!hasBeenWarned)
                      hasBeenWarned = true;
                      var warning = "Warning: You are about to be logged out in the next {0} minutes";
                      var mSecsBefore = new Date().getTime();
                      warning = warning.replace("{0}",minutesleftWarning);
                      var mSecsAfter = new Date().getTime();
                      secondsLeft = secondsLeft - (mSecsAfter - mSecsBefore)/1000;
                       secondsLeft = 125;
          if (secondsLeft < 1)
    <body onload="InitTimeoutCountdown()">
    <form name="mainform">

    <input type=text name=tbox> Seconds Left

    LVL 10

    Expert Comment

    you can also write a listner which implements HttpSessionListener. this listner will be called whenever a session is created and destroyed.

    you can write your code for setting the DB2 value in the sessionDestroyed method of the session listener. this sessionDestroyed method will be called whenever the session is invalidated or times out.

    Author Comment

    Hi mbvvsatish

    Do you have a example for this listener and how implement it?
    Also would this be called regardless of where the session timeout occurs. I.e. session timeout could be set on the WAS or within the web.xml. The current plan is to set it within the WAS.

    Thanks in advance.
    LVL 10

    Accepted Solution

    according to me it should be called regardless of where the session timeout is set(web.xml or WAS).

    here is an example on how to implement it

    its important to mention the listener in web.xml otherwise listeners wont work. hope you know this...

    Author Comment

    Thank you mbvvsatish. I had it working on Friday.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! How to Know You are Making a Difference at EE In August, 2013, one …
    Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
    This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now