Implementation of Java Listener online number display

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.