梦幻之旅

DEBUG - 天道酬勤

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  671 随笔 :: 6 文章 :: 256 评论 :: 0 Trackbacks
package com.test;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * 编写以下SessionCounter.java 并编译为SessiionCounter.class 
 * 然后放到你的网站的classpath的
 * SessionCount(自己建立此目录)下面
 
*/


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;
    }

}
然后需要在你的网站的WEB-INF中的web.xml 之中加入:
<web-app> 
    
<!-- Listeners --> 
     
<listener>
        
<listenerclass>com.test.SessionCounter</listener-class> 
     
</listener> 
</web-app> 
再重重新启动服务器就可以统计在线人数了.
posted on 2007-12-24 10:39 HUIKK 阅读(200) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: