java web在线人数统计
2017-07-21 16:41
513 查看
session并不是浏览器关闭时销毁的,而是在session失效的时候销毁下列代码就是监测session创建、销毁
写一个session.java
接下来就是配置web.xml
接下来就可以在jsp页面中使用
原文:http://www.cnblogs.com/tianguook/p/6115695.html
写一个session.java
package com.my.count; import javax.servlet.http.*; public class SessionCounter implements HttpSessionListener { private static int activeSessions = 0; //session创建时执行 public void sessionCreated(HttpSessionEvent se) { activeSessions++; } //session销毁时执行 public void sessionDestroyed(HttpSessionEvent se) { if (activeSessions > 0) activeSessions--; } //获取活动的session个数(在线人数) public static int getActiveSessions() { return activeSessions; } }
接下来就是配置web.xml
<listener> <listener-class> com.my.count.SessionCounter //这里是包名加类名 </listener-class> </listener>
接下来就可以在jsp页面中使用
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="com.my.count.SessionCounter"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'ApplicationTest.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 在线人数为:<%=SessionCounter.getActiveSessions() %> </body> </html>
原文:http://www.cnblogs.com/tianguook/p/6115695.html
相关文章推荐
- javaweb中实现在线人数统计
- JavaWeb中的application统计在线人数案例
- java web监听器统计在线用户及人数
- javaWeb 在线人数统计
- JavaWeb中的Session、SessionListener、在线人数统计
- javaweb中实现在线人数统计
- 简单的java web 统计在线人数实现方法
- java web 项目中通过session 统计在线访问人数
- Java Web开发——在线人数统计程序
- Java Web开发——在线人数统计程序
- javaweb中实现在线人数统计
- java统计在线人数详解|
- 统计在线人数Web
- java 实现统计在线人数
- java 页面在线访问人数统计和在线登录人数统计
- java统计在线人数
- 利用java监听器实现在线人数统计
- java 在线人数的统计
- java 统计在线人数(2)
- Java监听器学习 统计当前在线人数