[Webinar] Streamline your web hosting managementRegister Today

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

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.
0
ssheikh7
Asked:
ssheikh7
  • 2
  • 2
1 Solution
 
contactkarthiCommented:
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>
0
 
mbvvsatishCommented:
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.
0
 
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.
0
 
mbvvsatishCommented:
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
http://www.roseindia.net/servlets/ListenerSession.shtml

its important to mention the listener in web.xml otherwise listeners wont work. hope you know this...
0
 
ssheikh7Author Commented:
Thank you mbvvsatish. I had it working on Friday.
0

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