[Webinar] Streamline your web hosting managementRegister Today

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

Reset login indicator after session timeout.


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.
  • 2
  • 2
1 Solution
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

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.
ssheikh7Author Commented:
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.
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...
ssheikh7Author Commented:
Thank you mbvvsatish. I had it working on Friday.

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

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