I am developing a project purely on JSP and Servlets and require:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With