Is there any way to retrieve all of the active session ids on a server? The HttpSessionContext interface used to provide methods to do this, but has since been deprecated in the 2.1 API.

Rahul kumar Gupta

There is no way to get the all session ids apart from HttpSessionContext.

But you can implement it yourself with a collection.

Make a class that is using hash map or hash table object which is global to the application. Whenever a user logs in make an entry into hashmap or hash table and remove it when he/she logs out.

At any point you can retrieves keys and their values from that class that coresponds to user identification and session object.

for example if you are using JSP look at this code-


<jsp:useBean id="allsessions" scope="application" class="java.util.HashTable"/>


 String user=null;
 Enumeration users= allsessions.keys();
   user = users.nextElement();
   out.println("Userid ="+user);
   out.println("session = "+allsessions.get ((String)user));
[This code doesn't quite work -- where is "userid" acquired? How do you capture logout? But it's a nice hack anyway... -Alex]
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact