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? ?

[1104 byte] By [arijit_dattaa] at [2007-11-26 13:32:59]
# 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>

reflex2javaa at 2007-7-7 22:11:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
further to the above please checkout this discussion http://forums.devshed.com/html-programming-1/how-to-trap-window-close-event-of-browser-in-ie-1503.html
reflex2javaa at 2007-7-7 22:11:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
It's Simple, what you have to do is invalidate the current session when closing the window.
cybervink2000a at 2007-7-7 22:11:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Furthrr more you can update the database with a time stamp and check if the user logs in and see if his session is active, if it is active then check the timestamp is > 60 min. If that is true you can reset the time and authorize him.
reflex2javaa at 2007-7-7 22:11:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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!!

arijit_dattaa at 2007-7-7 22:11:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...