使用SessionListener统计在线人数
2007-07-24 11:33
381 查看
1.编辑监听类:
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
import org.apache.log4j.Logger;
/** *//**
* Session监听器
*/
public class SessionListener implements HttpSessionListener ...{
private Logger logger=Logger.getLogger(this.getClass());
private long count=0;
public synchronized void sessionCreated(HttpSessionEvent se) ...{
this.count=this.count+1;
se.getSession().getServletContext().setAttribute("count",this.count+"");
}
public synchronized void sessionDestroyed(HttpSessionEvent se) ...{
this.count=this.count-1;
se.getSession().getServletContext().setAttribute("count",this.count+"");
}
}
2.注册监听到web.xml:
<web-app>
...
<listener>
<listener-class>com.link2friend.friend.sessionlistener.SessionListener</listener-class>
</listener>
...
</web-app>
3.网页上使用:
<%=application.getAttribute("count")%>
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
import org.apache.log4j.Logger;
/** *//**
* Session监听器
*/
public class SessionListener implements HttpSessionListener ...{
private Logger logger=Logger.getLogger(this.getClass());
private long count=0;
public synchronized void sessionCreated(HttpSessionEvent se) ...{
this.count=this.count+1;
se.getSession().getServletContext().setAttribute("count",this.count+"");
}
public synchronized void sessionDestroyed(HttpSessionEvent se) ...{
this.count=this.count-1;
se.getSession().getServletContext().setAttribute("count",this.count+"");
}
}
2.注册监听到web.xml:
<web-app>
...
<listener>
<listener-class>com.link2friend.friend.sessionlistener.SessionListener</listener-class>
</listener>
...
</web-app>
3.网页上使用:
<%=application.getAttribute("count")%>
相关文章推荐
- 使用SessionListener统计在线人数
- php使用Session和文件统计在线人数
- JavaWeb中的Session、SessionListener、在线人数统计
- ASP.NET中使用Application对象实现简单在线人数统计功能
- 关于jsp内置对象Session和Cookie使用的肤浅理解,如何使用Session来统计网站在线人数
- JavaWeb中的Session、SessionListener、在线人数统计
- 用SessionListener实现统计在线人数及访问量
- 对jsp的一个小结(8)使用servlet控制新闻管理、使用过滤器(解决乱码)和监听器(统计在线用户人数)
- 在Global.asax中使用定时器来统计在线人数和每天每
- 关于jsp内置对象Session和Cookie使用的肤浅理解,如何使用Session来统计网站在线人数
- 使用HttpSessionListener接口监听Session的创建和失效(可以用于统计在线人数)
- 使用java 监听器实现在线人数统计
- 统计在线用户(在Global.asax中使用定时器来统计在线人数和每天每月的访问量 )
- java session HttpSessionListener、HttpSessionBindingListener使用区别,实现在线人数统计以及踢出用户
- 使用监听器实现一个统计网站在线人数的示例
- 使用HttpSessionBindingListener统计在线人数
- 使用HttpSessionListener统计在线人数
- Session、SessionListener、在线人数统计
- asp.net 使用Application和Session对象统计在线人数
- 用SessionListener实现统计在线人数及访问量