HttpSessionListener statistics online number

xiaoxiao2021-03-06  85

/ **

* 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:

Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"

"http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">

Sessioncount.SessionCounter

Then restart your application server, access online.jsp check if it is displayed correctly.

转载请注明原文地址:https://www.9cbs.com/read-121413.html

New Post(0)