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")%>
分享到:
相关推荐
这个资源是针对session容器的,在具有多个session的session容器里需要进行注册,所以就有了这个代码。不过写的还是很粗糙的。
jsp中唯一登录,使用session控制.
使用SessionListener+持久化Session+Springmvc拦截器实现单点登录
监控器需要的jar,需在web.xml中配置 <filter-name>monitoring ... <listener-class>net.bull.javamelody.SessionListener</listener-class> 通过web地址:http:xxxx/项目名/monitoring 可以进入到监控页面
javax.media.rtp.event ...通知SessionListener的数据包/ RTCP协议的数据包已经开始停止后抵达抵达。如果在一个活跃的发件人,这涉及到国家的数据包的ReceiveStream 。在被动的情况下接收器,在ReceiveStream将是无效
<listener-class>net.bull.javamelody.SessionListener</listener-class> 2、需监控的web工程引入依赖jar包 jira-javamelody.jar jrobin-1.5.9.1.jar 3、如果您的web项目有SpringSecurity,修改Spring...
- SessionListener: contextInitialized() - Starting Coyote HTTP/1.1 on http-8080 - JK: ajp13 listening on /0.0.0.0:8009 - Jk running ID=0 time=0/32 config=null - Find registry server-registry.xml at ...
{"time":"2017-09-06 10:24:48,649","logtype":"INFO","loginfo":"org.apache.catalina.core.ContainerBase.[Catalina].[bms-res.hzfh.com].[/examples]:SessionListener: contextInitialized()"} {"time":"2017-09-...