wood burning stoves 2.0*
The moose likes Servlets and the fly likes How do you get all sessions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How do you get all sessions?" Watch "How do you get all sessions?" New topic

How do you get all sessions?

K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Does the Servlet API allow you to retrieve all active sessions? I need to iterate through each one, looking for a particular attribute in the session and then invalidate the session.

I see that HttpSessionContext existed for some time before being removed. Any alternatives?

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

One alternative is to use a session listener and a context scoped map to store references to all the sessions.

There was a fairly detailed thread on this a while back.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
For security reasons you're not allowed to snoop through other sessions.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410


I agree. Here's the link: http://aspose.com/file-tools
subject: How do you get all sessions?
Similar Threads
HttpSession scalability?
are request attributes and session attributes thread safe?
HttpActivationListener question
Get session attribute values from all activated session's