🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 监听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(钝化和活化) ### 注意