HttpSessionListener statistics online number

xiaoxiao2021-03-06  81

/ ** * Write the following sessioncounter.java * and compile SESSIONCOUNTER.CLASS * and then put it on the classpath of your website * sessioncount; import javax.servlet; import javax.servlet. *; Import Javax. Servlet.http. *;

Public class sessioncounter implements httpsessionListener {

Private static int activitynesss = 0;

Public void sessioncreated (httpsessionever "{activityations ;}

Public void sessionDestroyed (httpsessionever se) {if (agentismions> 0) Activeisms-;

Public static int getActdomesions;}} then established an online.jsp file to display online number <% @ Page Import = "sessioncount.sessioncounter"%> Online: <% = sessioncounter.getActiveSessionS ()%> then need The contents of the Web.xml file in your website is as follows: sessioncount.sessioncounter then restart your application server, access online.jsp check if The display is correct.

------------------------------ BTW: MyListener can also achieve some other Listener interface, such as
ServletContextListener: in an application call start and end
ServletContextAttributeListener: an increase in the application, call
HttpSessionActivationListener deleted, and modified
Attributes: Session activation and deactivation of call
HttpSessionAttributeListener when a distributed environment: an increase in the session, Call
httpsessionBindingListener when deleting and modifying properties: is called to the Session.

转载请注明原文地址:https://www.9cbs.com/read-95175.html

New Post(0)