Web技术ListenerAPI
/**主要监听域对象的创建,属性修改,销毁。
*/
//ServletRequest域
ServletRequestListener srl = null;
//得到事件源,ServletRequestListener的事件处理对象
new ServletContextAttributeEvent(null, null, srl).getSource();
ServletRequestAttributeListener sral;
//得到操作的属性key。ServletRequestAttributeListener事件的处理对象
new ServletContextAttributeEvent(null, null, null).getName();
new ServletContextAttributeEvent(null, null, null).getValue();
//HttpSession域
HttpSessionListener hsl;
HttpSessionAttributeListener hsal;
//对象感知监听器(该对象想知道自己有没有放到session中就可实现该接口)。如果该对象被session绑定(保存到session中),就会触发
HttpSessionActivationListener hsal1;
//该对象(该对象必须实现序列化接口Serializable)有没有被session持久化到硬盘中。
HttpSessionBindingListener hsbl;
配置对象持久化到磁盘
在WebContext/META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- maxIdleSwap:session中的对象多长时间不使用就钝化 -->
<!-- directory:钝化后的对象的文件写到磁盘的哪个目录下 配置钝化的对象文件在 work/catalina/localhost/钝化文件 -->
<Manager className="org.apache.catalina.session.PersistentManager" maxIdleSwap="1">
<Store className="org.apache.catalina.session.FileStore" directory="itheima32" />
</Manager>
</Context>
//ServletContext域
ServletContextListener scl;
ServletContextAttributeListener scal;

浙公网安备 33010602011771号