How to check the number of client currently logged in ?

J

james

I am developed a web-application which support user authenication with
JSP/Javabean under Tomcat
I would like to know how I can let the jsp to display a counter which show
how many users are currently logged in the system ? Is there any function
call for it ?
Or shall I define some application scoped variable to handle it ?
 
?

=?ISO-8859-15?Q?G=E9din_Fr=E9d=E9ric?=

james said:
I am developed a web-application which support user authenication with
JSP/Javabean under Tomcat
I would like to know how I can let the jsp to display a counter which show
how many users are currently logged in the system ? Is there any function
call for it ?
Or shall I define some application scoped variable to handle it ?

I don't know how to do it using JSP. However, the servlet API provides the
HttpSessionBindingListener and HttpSessionBindingEvent interfaces which
will allow you to track every session binding or unbinding events. Then
you should be able to record the number of active sessions which should
reflect the number of logged in users. Of course, this has to be updated
with the actual user login activity:

- When the user logs in, you remember the session id and increments the
counter
- When the user logs out, you decrement the counter
- When the sessions unbinds, you decrement the counter

Hope this helps

Frederic
 
W

William Brogden

I don't know how to do it using JSP. However, the servlet API provides
the
HttpSessionBindingListener and HttpSessionBindingEvent interfaces which
will allow you to track every session binding or unbinding events. Then
you should be able to record the number of active sessions which should
reflect the number of logged in users. Of course, this has to be updated
with the actual user login activity:

- When the user logs in, you remember the session id and increments the
counter
- When the user logs out, you decrement the counter
- When the sessions unbinds, you decrement the counter

Actually the simplest thing to do is - when you get a "log out" just
invalidate the session - the listener will be called automatically.
If the user wanders off without logging out, you still get the event
when the session times-out.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top