/ ** * 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: XML Version = "1.0" eNCoding = "ISO-8859-1">
------------------------------ 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.