I have a web based application that uses userName and password for login.
now how can i check on certain time which all users are logged in at that very time.
i am using session management and no DB is used in application everything is on filesystem
Edit: 1 more silly doubt.. how to define a variable with application scope.. is this something of this sort?
<env-entry>
<env-entry-name>test/MyEnv2</env-entry-name>
<env-entry-type>java.lang.Boolean</env-entry-type>
<env-entry-value>true</env-entry-value>
</env-entry>
Just collect all logged in users in a
Setin the application scope. If your application is well designed, you should have a javabeanUserwhich represents the logged-in user. Let it implementHttpSessionBindingListenerand add/remove the user from theSetwhen it’s about to be bound/unbound in the session.Kickoff example:
Note that you need to prepare the
Setin the application scope so that it doesn’t returnnullin above methods. You could do that in the same methods by a nullcheck, or with help ofServletContextListener#contextInitialized().Then, anywhere in your application where you’ve access to the
ServletContext, like in a servlet, you can just access the logged-in users as follows: