aspose file tools*
The moose likes Servlets and the fly likes tracking active users in web app using Servlet event Listeners and j_username Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "tracking active users in web app using Servlet event Listeners and j_username " Watch "tracking active users in web app using Servlet event Listeners and j_username " New topic
Author

tracking active users in web app using Servlet event Listeners and j_username

Sven Anderson
Ranch Hand

Joined: Apr 14, 2004
Posts: 58
Hi all,

I'm writing an application where I want to track and display active users (users that are logged in).

My thought is to be able to do this by using the HttpSessionListener or any other of the Listener interfaces from the servlet API.

I've written a piece of code that counts number of users online using the HttpSessionListener interface.
This is fine for me, however I've got the problem in how to get the username from my j_username FORM authentication
(using Tomcat 4.x). My intention is to add each user to an array or map, but I want my implementation of the listeners to do the job. I just can't figure out how to get my listeners to get hold of the username

Many Thanks
Erik
Al Petersen
Greenhorn

Joined: Nov 27, 2004
Posts: 9
The only cross platform way to get the username of the currently authenticated user is to get it from the HttpServletRequest:

But, you can't get the request from the session. You could use a ServletRequestListener to get the request. Or instead of using a listener, you could use a filter...

- alan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: tracking active users in web app using Servlet event Listeners and j_username
 
Similar Threads
how to count active sessions in Servlet 2.2 specification
JBoss DatabaseServerLoginModule question...
Prevent Duplicate Logins
How many Session Objects ??
HttpSessionListener: What were they thinking?