Link to home
Start Free TrialLog in
Avatar of ssheikh7
ssheikh7

asked on

Reset login indicator after session timeout.

Hello,

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.
Avatar of contactkarthi
contactkarthi
Flag of United States of America image

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

<html>
<head>
<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;
      if(interval)
            clearInterval(interval);
      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);
                  alert(warning);
                  var mSecsAfter = new Date().getTime();
                  secondsLeft = secondsLeft - (mSecsAfter - mSecsBefore)/1000;
                  if(secondsLeft>1)
                   secondsLeft = 125;
            }
      }
      if (secondsLeft < 1)
            document.location.href="Login.aspx?Logout=Logout";
}
</script>
</head>
<body onload="InitTimeoutCountdown()">
<form name="mainform">

<input type=text name=tbox> Seconds Left
</form>

</body>
</html>
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.
Avatar of ssheikh7
ssheikh7

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of mbvvsatish
mbvvsatish
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you mbvvsatish. I had it working on Friday.