How to keep track of Loggedin user of my system


General J2EE: How to keep track of Loggedin user of my system

  1. Hi Java Gurus, I had written a Web Application using J2EE and its like an intranet website. When an Administrator has logged in he wants to see who are all the users currently logged in. To do this i thought of the following option: Put the UserId in the application scope(ServletContext) when a user logged into the system. And remove that userId from the applicationScope as soon as he logged out. But the problem with this is approach is when the user closed the browser with out logout i am not able to remove the userId from applicationScope. Can any one tell me how to send a request to a servlet when the browser is closed by the user?
  2. Maintaining the list of users/sessions in SessionContext is a good idea. But when you add or remove users from this list must be done using a session listener. So here, using the callback methods like sessionCreated, sessionDestroyed, you will be able to track the number of sessions currently in the system. (Even if the user closes the browser without logging out, the session will expire, which will invoke the sessionDestroyed method)
  3. Hi James, Thank you very much for your suggestion. Its working for me. Thanks, K. Siva Prasad Reddy.