aspose file tools*
The moose likes Servlets and the fly likes Viewing a list of all active users Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Viewing a list of all active users" Watch "Viewing a list of all active users" New topic
Author

Viewing a list of all active users

Rajesh Rajaram
Ranch Hand

Joined: Aug 20, 2002
Posts: 63
Hello All,

I have a requirement to list all the active sessions in the application. Is there any api or any other way of getting the active session. Its for the Administrator of the application.

regards

Rajesh


Rajesh Rajaram
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

sessions or users? Your subject and thread body don't really ask the same question.


GenRocket - Experts at Building Test Data
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18909
    
    8

If it's sessions you want to keep track of, then an HttpSessionListener sounds ideal. Documentation says

"Implementations of this interface may are notified of changes to the list of active sessions in a web application."
Rajesh Rajaram
Ranch Hand

Joined: Aug 20, 2002
Posts: 63
Greg,

Its with session, I need to show a report. Which will say Person X is online or Offline.

can we extract the username from the session with the application.

regards

Rajesh
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Hmm, well, not that I know of. I mean, it would be a security breech for one user session to be able to see any other user's session, regardless of the user's role.

How this is usually acomplished, from my personal experience, is to use HttpSessionListener. Basically, when a user logs in you would want to either store a flag in a database that says that user is logged in or store something in Application scope. When the user logs off and/or the user's session is invalidated, change said flag.

You can do this with an HttpSessionListener. Look it up.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Not a JSP question, so moved to the Servlets forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajesh Rajaram
Ranch Hand

Joined: Aug 20, 2002
Posts: 63
Thanks Greg, It won't be a security breach, Since adminstrator is going to view the information.

I will try HttpSessionListener.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Rajesh Rajaram:
Thanks Greg, It won't be a security breach, Since adminstrator is going to view the information.

I will try HttpSessionListener.


What I meant was if user a was able to see user b's session for whatever reason, you wouldn't be able to limit that to a role based situation. It wouild either be all or nothing, so it wouldn't be a secure thing to have availabel in the API, imho.
Rajesh Rajaram
Ranch Hand

Joined: Aug 20, 2002
Posts: 63
We have about 1000 users worldwide, suppose if we need to perform a maintence work like restarting some of the services, deploying new build , it should not destroy their work.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There used to be a sessionContext object but it was deprecated for the reasons Gregg listed.

SessionListeners make it easy to implement yourself.
I wrote a little sample app that does this.
http://simple.souther.us/not-so-simple.html
Look for Session Monitor.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rajesh Rajaram
Ranch Hand

Joined: Aug 20, 2002
Posts: 63
Thanks Ben, Appreciate your Input.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Viewing a list of all active users