This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Query regarding Session Tracking" Watch "Query regarding Session Tracking" New topic
Author

Query regarding Session Tracking

sachin warang
Greenhorn

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.

Regards,
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).

ram.
 
Don't get me started about those stupid light bulbs.
 
subject: Query regarding Session Tracking