Two Laptop Bag*
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 Murach's Java Servlets and JSP this week in the Servlets 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.
 
 
subject: Query regarding Session Tracking
 
Similar Threads
name of user
Form based authentication
Help Regarding about Session in jsp
Session Management Still weird
Session management with username