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

Browser close session destroy

pradeep gamage
Ranch Hand

Joined: Aug 03, 2009
Posts: 85

I have been working login handle by jsf,Spring and hibernate. I have created a login. but when i close the web browser user session still exist in web server. so that user can't log again until 30 min.
I have added following code part in web.xml

So what i want to do is that when user close browser or restart computer invalidate (User log session)the session in server side and allow that user to logging again. Please give me idea how to do my requirement?
thanks in advance

Software Engineer(BSC):SCJP 1.5
(Knowledge is power when applied)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

There is no way using server-side code to force the client to make one last server request when a browser is closed. And, in any event, there are too many ways for such a process to fail, starting with a simple browser crash and moving on up from there. For one thing, it takes more than closing a window to shutdown a browser.

Unless something really strange is going on, your sessionid cookie should have been destroyed when the final browser window closed, however. That would mean that even though the session object still existed and still held resources, the user wouldn't be requesting that session when restarting the browser and a whole new session would have to be built. When using the J2EE standard container-managed security system that would be sufficient to force the user to log in again.

So, presumably you're using a Do-It-Yourself login system. As I've said many times before, DIY systems are buggy, expensive, and insecure and should be avoided.

And, if by chance, you're manually meddling with the jsessionid appendage to the URL, I think that would explain why you're not discarding the old session when you should be.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Browser close session destroy
jQuery in Action, 3rd edition