• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Query regarding Session Tracking

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
session.getAttribute( "Username");
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic