Method of realizing online number monitoring function based on java servlet listener

This paper describes the method of realizing the function of online number monitoring based on java servlet listener. Share with you for your reference, as follows:

1. Analysis:

To make statistics on the number of people online, you can listen through servletcontextlistener. When the web application context is started, add a list in the ServletContext It is used to prepare and store the online user name, and then listen through HttpSessionAttributeListener. When the user logs in successfully, set the user name to session. At the same time, the user name method is added to the list of ServletContext. Finally, it is monitored through httpsessionlister. When the user logs off the session, the user name is deleted from the list in the application context.

2. Precautions

During the test, different browsers need to be started to log in to different users. Only clicking the logout button can reduce online users. Closing the browser can not reduce online users.

3. Project source code

(1) Java code

Onlinelistener class

Loginservlet class

Logoutservlet class

(2) Web.xml code

(3) Presentation layer code

For more information about Java algorithms, readers who are interested can see the topics on this site: summary of Java network programming skills, tutorial on Java data structure and algorithms, summary of Java DOM node skills, summary of java file and directory operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>