Enable sign out .. when window is closed.
We have all used emails.. etc.. where we need to sign in etc.. when we close the window.. using the ' x ' at the top we automatically get signed out.. its not a good practice.. but websites provide this support..
Now how do i enable that in my project?.. i have a 'sign out' option..which does the usial sign out..
although i used cookies for the retainment of username..i cant use it for that purpose.. its because this : when a user logs in.. his user name gets verified and logged on to a DB table... so that... when another user tries to simeltaneously log in from another computer using the same username and password, he gets a message 'user is already online. please use a differnt id'..
Now.. when the user closes the window.. the cookie gets destoryed.. and so does the session.. but how to remove the name from the DB table.. it remains behind.. ...
My sign out option does the jobs of removing the user from the table.. destorying the cookie and invalidating the session.
So how do I achieve the same thing when the user simply closes the window? ?
# 1
I think you need to use the javascript to enable the signout.
The signout can be done on closing the window event,
Here is the sample code,
<html>
<head>
<script language="javascript">
<!--
function callme() {
alert ('closing');
}
-->
</script>
</head>
<body onBeforeUnload="callme()">
<h1> Good Morning</h1>
</body>
</html>
# 5
relfex2java... i quite think that your solution with the JS is effective..Now this is what I will do.. instead of the alert being popped the JS will straightway load the 'Logout' servlet in the same window and and then using another JS which will be present in the Logout servlet close on its own. Therotically should be working!! **** neat!
Hey thanks for that tip about the time-stamp. I would rather do that with a cookie. As I had mentioned earlier I am already using cookies to store the username for session tracking. i will set the max age of the cookie to say 60 min.. and as soon 60 min is reached the cookie destorys.. and the session gets invalidated.. . as far as the time stamp goes.. well as soon as a user logs in the validation servlet validates him and records his time of entry.. and and logout servlet does just the opposite. ..logs his time of ext..
so thats taken well care of!
Thanks
Greetings for a Happy New Year!!