2020-03-26


一。

Servlet中的监听器的分类

一类:监听三个域对象的创建和销毁的监听器(三个)

二类:监听三个域对象的属性变更(属性添加、移除、替换)的监听器(三个)

三类:监听HttpSession中JavaBean的状态改变(钝化、活化、绑定、解除绑定)的监听(两个)

二、

ServletContext创建和销毁

创建:在服务器启动的时候,为每个Web应用创建单独的ServletContext对象

销毁:在服务器关闭的时候,或者项目从Web服务器中移除的时候

三。

ServletContextListener监听器的方法

监听ServletContext对象的创建

        contextInitialized(ServletContextEvent sce)

监听ServletContext对象的销毁

        contextDestroyed(ServletContextEvent sce)

四。

三类监听器

ServletContextAttributeListener

监听ServletContext对象中的属性变更(属性添加、移除、替换)的监听器

attributeAdded(ServletContextAttributeEvent event)

attributeRemoved(ServletContextAttributeEvent event)

attributeReplaced(ServletContextAttributeEvent event)

HttpSessionAttributeListener

监听HttpSession对象中的属性变更(属性添加、移除、替换)的监听器

attributeAdded(HttpSessionBindingEvent event)

attributeRemoved(HttpSessionBindingEvent event)

attributeReplaced(HttpSessionBindingEvent event)

ServletRequestAttributeListener

监听ServletRequest对象中的属性变更(属性添加、移除、替换)的监听器

attributeAdded(ServletRequestAttributeEvent srae)

attributeRemoved(ServletRequestAttributeEvent srae)

attributeReplaced(ServletRequestAttributeEvent srae)

五。

Servlet规范中中定义了两个特殊的监听的接口,来帮助Java类了解自己在Session域中的状态,分别是:HttpSessionBindingListener接口

HttpSessionActivationListener接口实现了这两个接口的类,是不需要在web.xml中进行配置的

六。

配置完成Session的序列化和反序列化

Context标签可以配置在:

Tomcat/conf/context.xml:所有Tomcat下虚拟主机和虚拟目录下的工程都会序列化Session

Tomcat/conf/Catalina/localhost/context.xml:只有localhost虚拟主机下的所有项目会序列化Session

工程/META-INF/context.xml:只有当前工程才会序列化Session

你可能感兴趣的:(2020-03-26)