ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 监听Javabean在session中的状态变化 ### HttpSessionBindingListener(解绑和绑定) 绑定 :Javabean放入了session. 解绑:Javabean从session中移除. 不需要配置web.xml文件. ~~~ public class Account implements HttpSessionBindingListener //需要实现此接口 { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } //重写下面两个方法 @Override public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent) { System.out.println("seesion和bean绑定了"); } @Override public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent) { System.out.println("seesion和bean解绑了"); } } ~~~ 绑定 ~~~ <% session.setAttribute("account", new Account()); %> ~~~ 解绑 ~~~ <% session.removeAttribute("account"); %> ~~~ ### HttpSessionActivationListener(钝化和活化) ### 注意