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

Query regarding Session Tracking

sachin warang

Joined: May 04, 2006
Posts: 8
Hi friends,

I'm using Session Tracking API.
where i set the attribute,
session.setAttribute( "Username", userID );
for all user who logged in.

Now while maintaing the session ,how can i get all the user's "Username" value who are logged in now.

Sachin Warang.
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
session.getAttribute( "Username");

Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Assuming that you create a new session for every logged in user, there's no straight forward approach to get the user name of all logged in users. This is because there is no api by which you can get a handle to all existing sessions.

One way to do this would be to override the HttpSessionListener interface and in the sessionCreated() method, retrieve the user name (you have to be careful here because this method may fire even before you add the attribute to the session) and store it somewhere. Similarly in the sessionDestroyed() method, you have to retrieve the user name and delete it from wherever you stored it in. (You can retrieve the attribute from the sesssion in this case).

Consider Paul's rocket mass heater.
subject: Query regarding Session Tracking
It's not a secret anymore!