Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: about the session


Message #1 by "shinetime" <shinetime@2...> on Fri, 1 Jun 2001 09:54:38 +0800
Unfortunately, the beforeUnload() method is highly unreliable. It, in 
fact, will not behave as the original post would want it to. This is 
documented in Netscape's documentation on Javascript.

The root of the difficulty is that there are several actions the user can 
administer in a web page that trigger the Unload() event. What the 
developer must do is "catch" all the actions the user does that do NOT act 
as closing the browser (ie, submit links,leaving your web links,etc). That 
way, the only remaining action the user takes will be considered closing 
the browser and your Unload() event will trigger for only that action. 
Hopefully the example I include can better demonstrate what I'm finding 
difficult to verbalize. ;)

Example :

Basically, you'll want to initialize a boolean called closing to true when 
you load a new page. You must do this for every page in your web that you 
want to incorporate this behavior.

<body onLoad="closing=true" onUnload="if (closing) 
window.location='<insert new page or new task for redirect 
here>';location.reload();">

Additionally, every link,action,etc that would cause the current page to 
call Unload(), needs to set closing to false so that the current page 
won't trigger the events you specified in the onUnload() method in the 
<body> tag.

<td><img src="../webapp_images/accountsTabs.gif" width="154" height="20" 
usemap="#AccountsTabs" border="0" onClick="closing=false"></td>

Hope this helps,

John Owen

> hi there is a javascript method that exists for
> windows that you could use to call another servlet
> that will invalidate the user
> 
> i believe it's called 
> windows.beforeunload();
> 
> stephen sutherland
> jsp/java consultant
> 
> --- Kevin Mukhar <kevin.mukhar@c...> wrote:
> > > From: "shinetime" <shinetime@2...>
> > > 
> > > How can I logout a user (invalidate his Session)
> > when a user directly closes
> > > his browser window?
> > 
> > Jaspal Muker wrote:
> > > 
> > > A session is automatically lost if the user closes
> > the browser since the
> > > session cookie expires when the user closes the
> > window.
> > 
> > The session is "lost" in the browser, but still
> > exists in the server. It will
> > exist until the session times out in the server.
> > That could be a short time or
> > a long time depending on how the server is
> > configured. One system I worked had
> > the timeout set to 24 hours.
> > 
> > Shinetime, you may want to go check the archives.
> > This issue is discussed
> > frequently, and was just discussed this about a
> > month ago. Here's the start of
> > that thread:
> >
> http://archives.java.sun.com/cgi-bin/wa?A2=ind0104&L=servlet-
interest&O=A&P=99133.

  Return to Index