监听器有very many的多,这里就用监听实时的在线人数来介绍-
public void sessionCreated(HttpSessionEvent se) {
ServletContext gsc = se.getSession().getServletContext();
Integer onlineperson = (Integer) gsc.getAttribute("onlineperson");
if(onlineperson==null){
onlineperson=new Integer(1);
}else{
int count = onlineperson.intValue();
onlineperson=new Integer(count+1);
}
gsc.setAttribute("onlineperson",onlineperson);
}
@Override
//销毁session监听
public void sessionDestroyed(HttpSessionEvent se) {
ServletContext gsc = se.getSession().getServletContext();
Integer onlineperson = (Integer) gsc.getAttribute("onlineperson");
if(onlineperson==null){
onlineperson=new Integer(1);
}else{
int count = onlineperson.intValue();
onlineperson=new Integer(count-1);
}
gsc.setAttribute("onlineperson",onlineperson);
<listener>
<listener-class>com.Google.OnlineLisetener</listener-class>
</listener>