我正在使用一个扩展 org.apache.wicket.protocol.http.WebSession 的会话类;当此会话因注销或超时而到期时,我需要调用一个方法。但我什么也没找到。我该怎么做?
Mohsen Ghafoorian
问问题
7154 次
2 回答
7
您可以像这样在 Wicket 级别执行此操作:
通过覆盖 SessionStore 实现 - 覆盖 Application#newSessionStore()
@Override
protected ISessionStore newSessionStore() {
return new SecondLevelCacheSessionStore(this, new DiskPageStore()) {
@Override
protected void onUnbind(String sessionId) {
// this code is called when wicket call httpSession.invalidate()
}
};
}
但这有一个缺点:当会话到期(由 servlet 容器控制)时,不会调用此代码。换句话说 - 您只能处理由 wicket 本身引起的会话销毁事件。
在全局级别上,您可以使用 Servlet API 的HttpSessionListener - 您可以对会话销毁事件做出反应,无论它是由什么触发的
HttpSesionListener#sessionDestroyed(HttpSessionEvent se)
并将其写入您的 WEB-INF/web.xml
<listener>
<listener-class>
your.listener.class.full.qualified.name
</listener-class>
</listener>
于 2009-10-08T11:46:06.583 回答
2
Session.java 有一个回调方法,当用户会话无效或由于 HttpSession 过期时执行。
public void onInvalidate(){
}
于 2015-06-09T08:50:13.087 回答