惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
IT之家
IT之家
Last Week in AI
Last Week in AI
J
Java Code Geeks
L
LangChain Blog
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
博客园 - Franky
博客园 - 司徒正美
月光博客
月光博客
博客园 - 叶小钗
Vercel News
Vercel News
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
B
Blog RSS Feed
人人都是产品经理
人人都是产品经理
H
Help Net Security
G
Google Developers Blog
D
DataBreaches.Net

博客园 - daniel-shen

精通EJB-概述 硬件基础知识大全 教程:关于XMLBeans的初步 在客户端进行xslt对xml的xuan渲染 jaxp笔记2007-4-17 6.ZK用户接口标记语言 5.事件的监听和处理 - daniel-shen - 博客园 4.组件的生命周期 3.zk体系结构 "tomcat启动分析"文章读后笔记 jdk5.0 范型说明 java 数组反射例子 HTML小技巧 MessageFormat初步 ResourceBundle 与locale的使用 jni中关于dll的装载问题 java线程-消费者vs生产者 用Java Servlets 2.4实现过滤 加和不加java:comp/env/前缀有什么区别?
HttpSessionBindingListener实现与应用
daniel-shen · 2006-10-24 · via 博客园 - daniel-shen

HttpSessionBindingListener接口有两方需要实现的方法:
public synchronized void valueBound(HttpSessionBindingEvent httpsessionbindingevent)
public synchronized void valueUnbound(HttpSessionBindingEvent httpsessionbindingevent)

Session创建的时候Servlet容器将会调用valueBound方法;Session删除的时候则调用valueUnbound方法.

具体应用可以跟踪每个在登录用户,记录相关的信息,以及在其超时的时候及时的删除相关的信息.

实例代码如下:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
....
....
public synchronized void valueBound(HttpSessionBindingEvent httpsessionbindingevent){
//检查是否有效
if(!Valid()) return;
//检查信息是否已经存在.不存在则添加.

if(Info.online.containsKey(m_userId))
{
//记录日志信息
log.info("initial user context....");
UserOnlineStruct UOS = (UserOnlineStruct)Info.online.get(m_userId);
UOS.loginIp = uos.loginIp;
UOS.loginTime = uos.loginTime;
UOS.sessionId = uos.sessionId;
}
else{
Info.online.put(m_userId, uos);
}
}

public synchronized void valueUnbound(HttpSessionBindingEvent httpsessionbindingevent){
//检查是否