This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Invalidate one session from another session." Watch "Invalidate one session from another session." New topic
Author

Invalidate one session from another session.

Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
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?
Thanks.


BJ - SCJP and SCWCD
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: 666
HttpSessionAttributeListener solved the problem.
Thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Vijay Rajaram
Greenhorn

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Invalidate one session from another session.
 
Similar Threads
session object
Session gets destroyed when invoking application of another server in a same browser
session management -session not destroying automatically
sendRedirect()
Session problem in Struts and Tomcat