是的,那是可能的。您可以使用方法来
HttpSessionListener完成这项工作
sessionDestroyed(),
@WebListenerpublic class MyHttpSessionListener implements HttpSessionListener { @Override public void sessionDestroyed(HttpSessionEvent event) { // Do here the job. } // ...}或者,
您可以让存储为会话属性的复杂对象实现
HttpSessionBindingListener并在
valueUnbound()方法中完成任务。
public class YourComplexObject implements HttpSessionBindingListener { @Override public void valueUnbound(HttpSessionBindingEvent event) { // Do here the job. } // ...}每当要从会话中删除对象时(无论是通过会话
HttpSession#removeAttribute()的无效还是由会话的无效/期满显式删除)都将调用该方法。



