>>> Rakesh Rajendran <[EMAIL PROTECTED]> 15-Jun-00 5:30:58 PM >>>

>How do i detect a window closing event of the browser
>window so that i can pass control to a controller servlet?

Ahhh... this is really hard.

Within a browser you've got 3 potential interactive forces:

1. the user
2. JavaScript
3. some other executable content, eg: an applet

Obviously 1. is not much good to you.


2. JavaScript can handle events like a window.close() but
unfortunately the options JavaScript has for talking to a servlet are
limited.

JS has no network interface - it has to use the browser to connect to
a servlet, ie: by submiting a form that points to the servlet.

So you could set up an event handler on window.close() which submits
a form that you've hidden in the document.

I have to confess that I've never tried this and I'm not sure it will
work (will the browser allow a SUBMIT when it's closing?)


3. is conceptually much better because JS can talk directly to it,
asking it to send some notification. As long as the applet was
downloaded from the same place you want to send the notification you
can just use a URLConnection to connect to the servlet and send the
message.

Alternately you could do the same with the destroy method.

Both methods are flakey however since JVMs in browsers are quite
unreliable.


>It would be great if somebody could come up
>with other alternatives.

My advice is "don't do it".

If you design like this you're fighting against the web. The web is a
massively distributed environment, it is just not designed to be used
like a traditional LAN client server app (where what you are doing is
normal).

Often people feel that some sort of logout is necessary but session
management is designed specifically to allow resources to timeout
cleanly rather than being specifically brought down by a logout
event.


If you post the reason why you want to do this peeps on the list can
probably suggest alternative design patterns or reassure you that what
you're trying to do is not necessary.


Nic Ferrier

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to