How to find all registered users and those users who access the site but are not logged in?

I develop the project exclusively on JSP and Servlets and require:

  • to show a list of registered users
  • and show the number of users who access the site without logging in.

Does the servlet server provide any solution?

I found this answer , this may answer my first question, but not in detail.

Also, in addition to the above two questions, I would also like to know if I can register the IP addresses of users accessing my site?

I’m still learning the various Java EE concepts and don’t know how to get started with this, so keeping that in mind, provide a starting point and some details on how these three things can be achieved. I would also appreciate if you could provide links or explanations that will help me understand the basic concepts.

+8
jsp servlets
source share
1 answer

The answer you refer to is correct, in the sense that you can rely on http sessions to track users, both identified and anonymous.

One of the mechanisms you want to see is the http listener interface (see http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSessionListener.html ). This allows you to be notified when sessions are created and destroyed. This will give you the opportunity to update the counters.

Regarding the question about the IP address, you can get it by calling getRemoteAddr () in the request object. If you are behind a reverse proxy, you may need to pay attention to its configuration.

+1
source share

All Articles