JSP Display online number code (from Jspchina)

Source: Internet
Author: User
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
*/

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!



Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.