js| Display | online | Number of people online
/**
* Write the following Sessioncounter.java
* and compiled to Sessiioncounter.class
* Then put it on the classpath of your website
* Sessioncount (build this directory yourself) below
*/
Package sessioncount;
Import javax.servlet.*;
Import javax.servlet.http.*;
public class Sessioncounter implements Httpsessionlistener {
private static int activesessions = 0;
public void sessioncreated (Httpsessionevent se) {
activesessions++;
}
public void sessiondestroyed (Httpsessionevent se) {
if (activesessions > 0)
activesessions--;
}
public static int getactivesessions () {
return activesessions;
}
}
Then create a online.jsp file to display the number of people online
<%@ page import= "Sessioncount.sessioncounter"%>
Online: <%= sessioncounter.getactivesessions ()%>
Then you need to build web.xml in the Web-inf of your site.
The contents of the document are as follows:
<!--Web.xml-->
<?xml version= "1.0" encoding= "Iso-8859-1"?>
<! DOCTYPE Web-app
Public "-//sun Microsystems, INC.//DTD Web application 2.3//en"
"Http://java.sun.com/j2ee/dtds/web-app_2.3.dtd" >
<web-app>
<!--Listeners-->
<listener>
<listener-class>
Sessioncount.sessioncounter
</listener-class>
</listener>
</web-app>
Then restart your application server and access the online.jsp check to see if the display is correct.
This procedure in FreeBSD resin2.0.4 debugging success, please advise!