In the world of yards farm only bug can let people grow, the more bugs you encounter, the more efficient you will be!
The listener in Java is divided into three types: servletRequestListener, HttpSessionListener, servletContextListener;
servletrequest--requests occur when a client requests (accesses) a server, and the request occurs once (regardless of request forwarding).
The end of the request, the object is destroyed;
httpsession--session, a single user over a period of time (Tomcat defaults to 30min, can be set), since the first request (access)
When created, the object is destroyed until it expires;
The servletcontext--context, which exists on the server side, is created from the time the server is opened, until the server shuts down the object for destruction.
Then, there is a way of thinking: a user continued access to the site, the number of requests will be many, but the user has repeatedly requested the session is a
Straight is one (uniqueness). We can save the ID of the session object to the server (context) on the first visit, and each subsequent request
Time, we can check if the requested session object is already in the server (context), if at that point, indicate the request and some time before
The request is the same user, and if not, the ID of the new Session object generated by the request is stored in the server (context). Session object to
Period, the nature is destroyed (can be seen as a user for a long time each activity, forced to go offline), then the SessionID is located in the entire message deleted, but also
Can be seen as the reduction of one of the current access users. In fact, in addition to the multiple requests generated by the session is unique, the requesting device is also
Unique, we can identify by acquiring the IP of the device. We can store these two messages in the user class, each with a user object that has this
Two attributes, and is unique.
1.ServletRequest
Implementation of Java Listener online number display