Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all logged-in users and those users who are accessing the site but havn't logged-in?

Tags:

jsp

servlets

I am developing a project purely on JSP and Servlets and require:

  1. to show a list of logged-in users
  2. and show the number of users accessing the site without login.

Does the Servlet API provide some solution to this?

I found this answer, this might answer my first question but is not detailed enough.

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

I am still studying the various concepts of Java EE and doesn't know how to start on this, so keeping this in mind please provide a starting point and a little detail as to how these three things can be achieved. Also I would be grateful if you can provide links or explanation which will help me understand the underlying concepts.

like image 973
Chaitanya Marathe Avatar asked Oct 20 '12 12:10

Chaitanya Marathe


1 Answers

The answer that you are linking to is correct, in the sense that it is possible to rely on http sessions to track users, both identified and anonymous.

One mechanism that you want to look at 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. That will give you the way to update your counters.

As for the question about IP address, you can get by calling getRemoteAddr() on the request object. If you are behind a reverse proxy, you might have to pay attention to its configuration.

like image 67
Olivier Liechti Avatar answered Nov 02 '22 22:11

Olivier Liechti