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

Invalidate one session from another session.

Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 672
When a PC closes a browser, the session on the server is still alive. When the same PC opens up another browser I want to invalidate the first session from the new session.
This is to prevent many sessions for the same PC on the server.
Is there a way to do this?

We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 672
HttpSessionAttributeListener solved the problem.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33117

How do you check it is the same user? IP Address?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Vijay Rajaram

Joined: Nov 17, 2003
Posts: 12
To my knowledge the HttpSessionAttributeListener interface is useful only to get notified whenever an attribute is added/removed/changed in the session. In fact you have interface (HttpSessionBindingListener) which can be used to get notified when a session gets expired or invalidated. But you don�t have anything handy for your requirement. Please let us know your logic of using HttpSessionAttributeListener for this requirement. In my way, the best way to do is to invalidate the session when closing the browser rather than keeping it in the server till you create the next session or session timeout. You can do this by calling a java script function in the onUnload event of the page and invalidate the session using invalidate() method of the session object.
Note: onUnload function would be triggered even when you close the browser.
If someone have a better solution to the requirement or any conflict to my view, please let me know.
- VJ
I agree. Here's the link:
subject: Invalidate one session from another session.
It's not a secret anymore!