夢幻之旅

          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 閱讀(212) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 兴城市| 颍上县| 凯里市| 张家界市| 仙桃市| 郎溪县| 黔西| 六安市| 巫溪县| 佳木斯市| 江津市| 阳城县| 宁国市| 云安县| 江达县| 礼泉县| 新津县| 崇州市| 桃江县| 新丰县| 永平县| 边坝县| 平凉市| 兴仁县| 来宾市| 华安县| 杭锦旗| 原平市| 桐梓县| 西平县| 修武县| 内丘县| 富顺县| 隆尧县| 南江县| 南开区| 苏尼特右旗| 秭归县| 沾益县| 昌黎县| 安阳市|