js| Display | online | online number/**
* 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
*/
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" >
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service