Switch to full style
What's behind JSP & Servlets
Post a reply

tomcat session tracking

Wed Oct 22, 2008 1:50 am

As a part of my project (using servlets and tomcat 6 webserver), I want
to list all active tomcat sessions. Can anybody help me with source
code.



Re: tomcat session tracking

Wed Oct 22, 2008 1:51 am

* 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"/>

...

Code:
<%
allsessions.put(userid,session);
String user=null;
Enumeration users= allsessions.keys();
while(users.hasMoreElements())
{
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...

Post a reply
  Related Posts  to : tomcat session tracking
 How can I enable session tracking for JSP pages if the brows     -  
 tomcat server config     -  
 session in jsp     -  
 PHP session variables     -  
 EJB session bean     -  
 Session Valid     -  
 php login with session     -  
 Delete session variable     -  
 Session handling using Struts     -  
 Login using session with php and mysql     -