hyljava

          監(jiān)聽器實(shí)現(xiàn)獲取網(wǎng)絡(luò)在線人數(shù)

          首先寫一個(gè)計(jì)數(shù)的類OnlineCounter

          package accp.onlinecounter;

          public class OnlineCounter {
           private static long online = 0;

           public static long getOnline() {

            return online;

           }

           public static void raise() {

            online++;

           }

           public static void reduce() {
            online--;

           }
          }


          之后寫一個(gè)實(shí)現(xiàn)HttpSessionEvent的類OnlineCounterListener

          package  accp.onlinecounter;

          import javax.servlet.http.HttpSessionEvent; 

            import javax.servlet.http.HttpSessionListener;
            public class OnlineCounterListener implements HttpSessionListener {
            public void sessionCreated(HttpSessionEvent hse) {
             OnlineCounter.raise();
           }

            public void sessionDestroyed(HttpSessionEvent hse) {

            OnlineCounter.reduce();
            }
            }

          在web.xml中寫listener的注冊(cè)信息
             <listener>
            <listener-class>
            accp.onlinecounter.OnlineCounterListener
            </listener-class>
              </listener>
          前臺(tái)界面寫上

            <body>
           在線人數(shù): <%=OnlineCounter.getOnline() %><br/>
             <a href="adcourse.jsp">添加課程add course</a><br/>
             <a href="adds.jsp">添加學(xué)生add stu</a><br/>
             <a href="findallcourse.jsp">查詢課程信息 select course</a><br/>
              <a href="findallstudent.jsp">查詢學(xué)生信息 select student</a><br/>
              <a href="addstudentcourse.jsp">添加選課信息add student course</a><br/>
                <a href="querystucourse.jsp">查詢選課信息query student course</a><br/>
            
            </body>
          注意引入包即可

          posted on 2012-05-28 19:12 何云隆 閱讀(369) 評(píng)論(0)  編輯  收藏 所屬分類: Jsp

          主站蜘蛛池模板: 东宁县| 鲁甸县| 新沂市| 新津县| 阿勒泰市| 定西市| 雷山县| 乌审旗| 奉节县| 额敏县| 木兰县| 田阳县| 卢龙县| 浑源县| 阜宁县| 兴和县| 上高县| 沭阳县| 东莞市| 江永县| 聊城市| 烟台市| 余姚市| 哈密市| 若羌县| 黔江区| 平和县| 怀柔区| 那坡县| 遵化市| 印江| 上犹县| 德昌县| 绩溪县| 定日县| 张北县| 鹤壁市| 渝中区| 安新县| 新余市| 会昌县|