/ **
* Write the following sessioncounter.java
* And compile as sessiioncounter.class
* Then put it in the ClassPath of your website.
* Sessioncount (establish this directory yourself)
* /
Package sessioncount;
Import javax.servlet. *;
Import javax.servlet.http. *;
Public class sessioncounter implements httpsessionListener {
Private static int activitynesss = 0;
Public void sessioncreated (httpsessioneverment se) {
ActiveSessionS ;
}
Public void sessiondestroyed (httpsessionever se) {
IF (ActiveSESSES> 0)
Activeismions
}
Public static int getActivenesss () {
Return Activeism;
}
}
Then establish an online.jsp file to display the number of online people
<% @ page import = "sessioncount.sessioncounter"%>
Online: <% = sessioncounter.getActiveations ()%>
Then you need to build web.xml in your website's web-infers.
The document content is as follows:
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"
"http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">
Sessioncount.SessionCounter
listener-class>
listener>
web-app>
Then restart your application server, access online.jsp check if it is displayed correctly.