File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes regrding window closing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "regrding window closing" Watch "regrding window closing" New topic

regrding window closing

Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
Currently i am facing a problem.I have a form which can be opened by only 1 user at any given moment of time.When someone else tries to open the form (opened by someone else),he shoould get an error msg informing that the form is opened by "personName".Ihave set a flag in the database
if opened==Y show error msg
if opened==n allow to open the form.
For this i am storing the username in session var .
The prob i'm facing is that when the user(after opening form) closes the browser window,the database flag stays active ie ='Y'.
Can i have a window closing event so that if he closes the browser,his session will be invalidated?
Or can u suggest some other way?
Any help is appreciated.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
You can't detect the window closing on the server side, it can only be done client side with javascript. You need to figure out a way for the javascript to communicate with the servlet on the server, an applet might do it for you.
You can also have the flag expire when the current session ends too, you can detect that server side. In fact you almost have to in case for some reason the client side never lets the server know the window was closed.
hope that helps

Erick Jones
Ranch Hand

Joined: Jun 17, 2002
Posts: 38
Even with javascript there is not a good way to be notified when the user closes the window, unless you provide a logout button. But that will not handle the case when the user just uses the 'x' in the upper right hand corner.
Shubhrajit Chatterjee
Ranch Hand

Joined: Aug 23, 2001
Posts: 356
There is no foolproof method with Javascript as NS4.7 does not suppport trapping of unload event and in any case the client can always disable Javascript. Do it at the server-side by trapping the session time out.
Crude method ...
Keep the session time-out value low, use a frame and refresh one part of the frame continuously. This will keep the session alive when the page is open. When the page is closed in the browser, it will time out quickly.

I agree. Here's the link:
subject: regrding window closing
It's not a secret anymore!