The moose likes Servlets and the fly likes How to track all sessions? 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 "How to track all sessions?" Watch "How to track all sessions?" New topic

How to track all sessions?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
I want to create a page where I can list everyone (along with their current search term) that is logged into my site with a valid session.

Can anyone advise the best way of going about this?

Sudipta Laha
Ranch Hand

Joined: Aug 23, 2010
Posts: 49

If i am correct this may be one of the way, but there may be better implementations.

When the user login a session object is created for that user and is used for his session till he logs out. We may store a string containing the current search details in the session object.
For retrieving the details of all the sessions, we may store the session object in a map(when the user logs in) and when we delete/invalidate a session we may remove it from the map.

Any modification made in the session object for a user will also be available in the map. So its can be used to display all the sessions.

Some places DBs are also used to store session object.

Sudipta Kumar Laha
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Thanks Sudipta,

Is the best (only?) way to detect session deletion/invalidation via the HttpSessionListener and it's sessionDestroyed method?

Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

So far that i know, the only way to know if a session it is about to be destroyed it is by HttpSessionListener.

If you want, you can record who is logged through RequestListener or Filter. It's up to you.

[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Thanks very much to you both for the help - HttpSessionListener's sessionCreated and sessionDestroyed methods did the job.
subject: How to track all sessions?
Similar Threads
Idle's mind is a devils workshop
May 31, 2001 - test Job Offer $xxx,xxx Colorado Springs
No Banner for JSF book promo?
Brain Teasers