一、对servletContext、request、session域的监听器(六个监听器)
要使用这六个监听器时候步骤如下:
1、建立一个类去实现要使用监听器的接口;
2、在webapp文件夹下WEB-INF下的web.xml中进行配置;
①、ServletContextListener
②、HttpSessionListener
③、ServletRequestListener
这三个是监听器是对servletContext、request、session这三个域的开启和关闭进行监听。(里面需要实现两个事件:创建和销毁)
④、ServletContextAttributeListener
⑤、HttpSessionAttributeListener
⑥、ServletRequestAttributeListener
这三个是监听器是对servletContext、request、session这三个域中对象的修改、添加、删除进行监听(里面要实现三个事件修改、添加、删除)。
二、对session域的中感知监听器(两个)
使用这两个监听器时不需要在web.xml中进行配置。
①、HttpSessionBindingListener
这个是需要先创建一个bean对象类让对象类实现HttpSessionBindingListener接口中的绑定和解绑事件,每当session中存入该对象时候HttpSessionBindingListener的绑定事件就会运行,而每当session中的该对象移除时候解绑事件就会运行。