監(jiān)聽器
ServletContextListener 監(jiān)聽servlet的初始化和結(jié)束
httpSessionListener 監(jiān)聽session的創(chuàng)建和結(jié)束 ,可以利用這個(gè)來統(tǒng)計(jì)在線登錄的人數(shù)..
package com.zh;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class LoginListener implements HttpSessionListener{
private static int count;
public static int getCount(){
return count;
}
public void sessionCreated(HttpSessionEvent arg0) {
// TODO Auto-generated method stub count++;
}
public void sessionDestroyed(HttpSessionEvent arg0) {
// TODO Auto-generated method stub count--;
}
}
注意要在web.xml文件中 設(shè)置
com.zh.Test1
ServletContextAttributeListener 當(dāng)servletContext對象被設(shè)置,刪除,替換
HttpSessionAttributeListener 當(dāng)HttpSession對象被設(shè)置,刪除,替換
ServletRequestAttributeListener 當(dāng)ServletRequest對象被設(shè)置,刪除,替換
HttpSessionBindingListener 當(dāng)HttpSession中添加屬性和刪除屬性
注意: HttpSessionBindingListener不用在web.xml中設(shè)置
監(jiān)聽器ServletContextListener 監(jiān)聽servlet的初始化和結(jié)束
httpSessionListener 監(jiān)聽session的創(chuàng)建和結(jié)束 ,可以利用這個(gè)來統(tǒng)計(jì)在線登錄的人數(shù)..
package com.zh;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class LoginListener implements HttpSessionListener{
private static int count;
public static int getCount(){
return count;
}
public void sessionCreated(HttpSessionEvent arg0) {
// TODO Auto-generated method stub
count++;
}
public void sessionDestroyed(HttpSessionEvent arg0) {
// TODO Auto-generated method stub
count--;
}
}
注意要在web.xml文件中 設(shè)置
ServletContextAttributeListener 當(dāng)servletContext對象被設(shè)置,刪除,替換
HttpSessionAttributeListener 當(dāng)HttpSession對象被設(shè)置,刪除,替換
ServletRequestAttributeListener 當(dāng)ServletRequest對象被設(shè)置,刪除,替換
HttpSessionBindingListener 當(dāng)HttpSession中添加屬性和刪除屬性
注意: HttpSessionBindingListener不用在web.xml中設(shè)置