In a servlet 2.3 environment (Tomcat 4), you can accomplish your goal
without getting into the innards of the container. Simple create and
register an HttpSessionListener, which will be notified every time a
session within your app is created or destroyed -- it's easy to maintain a
local HashMap (or something) of the currently active sessions.
Does anyone know if there's a way to get some kind of a reference to all of
the active sessions in a webapp? I just want to know how many Sessions
I'd just like to be able to say something like "There are currently X Number
of users online" on some page.
This is Mike, posting a request/response email from two other people, one of whom is named Craig.
(At least one) solution to your problem is *in* that quote. Extrapolate beyond the information given. Think HashMap.size()
[ January 16, 2002: Message edited by: Mike Curwen ]
What u need to do is this ..
1) u need to declare a Haspmapor a Hashtable in the class. This u must me doing(i hope) to keep track, that the user doesnt log on two from two machine simaltaneously , any how even if u havent ,no problem .
2) everytime a user logs on to the ur web
application u have to check whether his login name is already there or not . if it is not there u put his name in the map .
3) every time a person logs out, u remove his name from the hashmap
4) now to find out what exactly ur requirement is what u can do is , u can call size() of the hashmap or table .which will return u the count of number of people who are using your application