目录
1. Filter & 过滤器
1.1. 过滤器概述
1.2. 过滤器的使用
1.3. 过滤器生命周期
1.4. 过滤器链的使用
1.5. 注解方式配置过滤器
2. Listener & 监听器
2.1. 监听器概述
2.2. Java Web的监听器
2.2.1. 常用监听器
2.2.1.1. ServletContextListener监听器
2.2.1.2. ServletContextAttributeListener监听器
2.2.2. 其他监听器
2.2.2.1. session域监听器
2.2.2.2. HttpSessionListener 监听器
2.2.2.3. HttpSessionAttributeListener 监听器
2.2.2.4. request域监听器
2.2.2.5. ServletRequestListener 监听器
2.2.2.6. ServletRequestAttributeListener 监听器
2.2.3. session域的两个特殊监听器
2.2.3.1. HttpSessionBindingListener 监听器
2.2.3.2. HttpSessionActivationListener 监听器
Filter是Java Web开发中的一种技术,它可以对目标资源的请求进行过滤。简单来说,Filter就像是一个前置处理器或者拦截器,它会在目标资源被请求之前执行,对请求进行一定的处理或者拦截。
举个例子:
生活举例中,公司前台、停车场安保和地铁验票闸机都是Filter的典型应用。它们都可以对进入的人员或者车辆进行审核和过滤。如果符合条件,就放行;如果不符合条件,就拒绝进入。同时,它们也可以在人员或者车辆离开时进行再次审核和收费。
Filter工作原理图解:
Filter接口API:
从IDEA上面的Filter.java上扒下来的源码,也就三个抽象方法:
目标:开发一个日志记录过滤器
LoggingFilter.java 过滤器
package filter;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class LoggingFilter implements Filter { //实现Filter接口
public void init(FilterConfig config) throws ServletException {
System.out.println("以启用登录过滤器~");
}
private final SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
// 参数父转子
HttpServletRequest request =(HttpServletRequest) servletRequest;
HttpServletResponse response =(HttpServletResponse) servletResponse;
// 拼接日志文本
String requestURI = request.getRequestURI();
String time = dateFormat.format(new Date());
String beforeLogging =requestURI+"在"+time+"被请求了";
// 打印日志
System.out.println(beforeLogging);
// 获取系统时间
long t1 = System.currentTimeMillis();
// 放行请求
filterChain.doFilter(request,response);
// 获取系统时间
long t2 = System.currentTimeMillis();
// 拼接日志文本
String afterLogging =requestURI+"在"+time+"的请求耗时:"+(t2-t1)+"毫秒";
// 打印日志
System.out.println(afterLogging);
}
@Override
public void destroy() {
System.out.println("以销毁登录过滤器~");
}
}
配置web.xml
不配置web.xml就是普通的java类,无法实现filter过滤器的功能
loggingFilter
filter.LoggingFilter
loggingFilter
/*
说明:
ServletA.java
package servlet;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/servletA")
public class ServletA extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp){
// 处理器请求
System.out.println("servletA处理请求的方法,耗时10毫秒");
// 模拟处理请求耗时
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
ServletB.java
package servlet;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/servletB")
public class ServletB extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp){
// 处理器请求
System.out.println("servletB处理请求的方法,耗时15毫秒");
// 模拟处理请求耗时
try {
Thread.sleep(15);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
启动服务器
Filter在Web项目中是一个重要的组件,其生命周期与Servlet有些类似,但也有一些区别。
阶段 |
对应方法 |
执行时机 |
执行次数 |
创建对象 |
构造器 |
web应用启动时 |
1 |
初始化方法 |
void init(FilterConfig filterConfig) |
构造完毕 |
1 |
过滤请求 |
void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) |
每次请求 |
多次 |
销毁 |
default void destroy() |
web应用关闭时 |
1次 |
过滤器链概述:
在一个Web项目中,可以定义多个过滤器(Filter)。这些过滤器可以同时存在,并且可以对同一个资源进行过滤操作。这些过滤器按照一定的顺序形成一个工作链,这个工作链被称为过滤器链(Filter Chain)。
示例:
如果定义了三个过滤器Filter1、Filter2、Filter3,执行顺序也是1、2、3
这里Filter的代码就不举例了,关键在于web.xml的写法
filter1
filters.Filter1
filter2
filters.Filter2
filter3
filters.Filter3
filter1
/servletC
filter2
/servletC
filter3
/servletC
注解方式配置过滤器是指在Java Web应用程序中使用注解来定义和配置过滤器。
和servlet注解类似,通过注解,可以省略web.xml配置文件,直接在Java类中声明过滤器。
Filter注解源码(还是从IDEA上面复制下来的):
package javax.servlet.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.servlet.DispatcherType;
/**
* Annotation used to declare a servlet filter.
*
* This annotation is processed by the container at deployment time,
* and the corresponding filter applied to the specified URL patterns,
* servlets, and dispatcher types.
*
* @see javax.servlet.Filter
*
* @since Servlet 3.0
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface WebFilter {
/**
* The description of the filter
*
* @return the description of the filter
*/
String description() default "";
/**
* The display name of the filter
*
* @return the display name of the filter
*/
String displayName() default "";
/**
* The init parameters of the filter
*
* @return the init parameters of the filter
*/
WebInitParam[] initParams() default {};
/**
* The name of the filter
*
* @return the name of the filter
*/
String filterName() default "";
/**
* The small-icon of the filter
*
* @return the small-icon of the filter
*/
String smallIcon() default "";
/**
* The large-icon of the filter
*
* @return the large-icon of the filter
*/
String largeIcon() default "";
/**
* The names of the servlets to which the filter applies.
*
* @return the names of the servlets to which the filter applies
*/
String[] servletNames() default {};
/**
* The URL patterns to which the filter applies
* The default value is an empty array.
*
* @return the URL patterns to which the filter applies
*/
String[] value() default {};
/**
* The URL patterns to which the filter applies
*
* @return the URL patterns to which the filter applies
*/
String[] urlPatterns() default {};
/**
* The dispatcher types to which the filter applies
*
* @return the dispatcher types to which the filter applies
*/
DispatcherType[] dispatcherTypes() default {DispatcherType.REQUEST};
/**
* Declares whether the filter supports asynchronous operation mode.
*
* @return {@code true} if the filter supports asynchronous operation mode
* @see javax.servlet.ServletRequest#startAsync
* @see javax.servlet.ServletRequest#startAsync(ServletRequest,
* ServletResponse)
*/
boolean asyncSupported() default false;
}
对源码进行分析:
@Target({ElementType.TYPE})
: 这个注解只能应用于类级别。@Retention(RetentionPolicy.RUNTIME)
: 这个注解将在运行时保留,在运行时可以被反射API读取。@Documented
: 这个注解会被包含在用户的JavaDoc中。String description() default "";
: 返回过滤器的描述,默认为空字符串。String displayName() default "";
: 返回过滤器的显示名称,默认为空字符串。WebInitParam[] initParams() default {};
: 返回过滤器的初始化参数,默认为一个空数组。String filterName() default "";
: 返回过滤器的名字,默认为空字符串。String smallIcon() default "";
: 返回过滤器的小图标,默认为空字符串。String largeIcon() default "";
: 返回过滤器的大图标,默认为空字符串。String[] servletNames() default {};
: 返回过滤器应用到的Servlet名字,默认为一个空数组。String[] value() default {};
: 和urlPatterns()
方法相同,返回过滤器应用到的URL模式,默认为一个空数组。String[] urlPatterns() default {};
: 返回过滤器应用到的URL模式,默认为一个空数组。DispatcherType[] dispatcherTypes() default {DispatcherType.REQUEST};
: 返回过滤器应用到的调度类型,默认为REQUEST。boolean asyncSupported() default false;
: 声明过滤器是否支持异步操作模式,默认为false。代码示例:
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import java.io.IOException;
@WebFilter(filterName = "MyFilter", urlPatterns = {"/welcome"})
public class MyFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// 初始化操作,如读取配置参数等
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
System.out.println("Before processing request");
// 调用下一个过滤器或servlet
chain.doFilter(request, response);
System.out.println("After processing request");
}
@Override
public void destroy() {
// 清理资源等
}
}
Listener 监听器是 JavaWeb 应用程序中的一种组件,它是 Servlet、Filter 和 Listener 这三个组件之一。Listener 是 Java EE 规范中的一部分,它是一个接口,用于监听特定事件或变化,并在触发时执行相应的任务。
监听器的作用是监听特定的对象或事件,例如对象的创建/销毁或属性变化等,当这些事件发生时,监听器会触发对应的方法来完成相应的任务。
有八个常用的监听器
其中最常用的是 ServletContextListener和ServletContextAttributeListener
举个例子:
监听器可以比喻为“报警器”。比如我们在家里安装的烟雾报警器,当烟雾达到一定浓度时,报警器就会发出警报,提醒我们可能有火灾隐患。这个报警器就是“监听器”,它监听的是烟雾浓度这个事件。当烟雾浓度达到设定阈值时,它就会触发警报。
在JavaWeb应用程序中,监听器也是类似的原理。比如ServletContextListener,它监听的是ServletContext对象的变化。当ServletContext对象创建或销毁时,ServletContextListener就会触发对应的方法来完成相应的任务。
监听器分类:
根据所监听的对象和事件的不同,可以将监听器大致分为以下几类:
在Java Web监听器中,常用的监听器是
ServletContextListener 和 ServletContextAttributeListener
ServletContextListener: 这个接口提供了一个监听器,可以监听ServletContext对象的创建和销毁事件。当Web应用程序启动时,会创建一个ServletContext对象,而在应用程序关闭时,该对象将被销毁。通过实现ServletContextListener接口,可以在这两个关键时刻执行特定的操作。例如,可以在ServletContext对象创建时初始化一些全局变量或执行其他必要的设置,或在对象销毁时进行资源清理。
ServletContextAttributeListener: 这个接口提供了一个监听器,可以监听ServletContext属性(即在ServletContext对象中存储的属性)的添加和移除事件。可以通过实现这个接口来监听特定属性的添加或移除操作,并在这些操作发生时执行特定的操作。例如,当某个属性被添加到ServletContext时,可以进行一些初始化操作;当某个属性被移除时,可以执行一些清理操作。
ServletContextListener监听器:监听ServletContext对象的创建与销毁
ServletContextListener本身就是一个接口,继承EventListener接口
相关方法:
方法名 |
作用 |
contextInitialized(ServletContextEvent sce) |
ServletContext创建时调用 |
contextDestroyed(ServletContextEvent sce) |
ServletContext销毁时调用 |
ServletContextListener的源码,一个继承与EventListener的接口
package javax.servlet;
import java.util.EventListener;
public interface ServletContextListener extends EventListener {
/**
* Receives notification that the web application initialization
* process is starting.
*
* All ServletContextListeners are notified of context
* initialization before any filters or servlets in the web
* application are initialized.
*
* @param sce the ServletContextEvent containing the ServletContext
* that is being initialized
*
* @implSpec
* The default implementation takes no action.
*/
default public void contextInitialized(ServletContextEvent sce) {}
/**
* Receives notification that the ServletContext is about to be
* shut down.
*
*
All servlets and filters will have been destroyed before any
* ServletContextListeners are notified of context
* destruction.
*
* @param sce the ServletContextEvent containing the ServletContext
* that is being destroyed
*
* @implSpec
* The default implementation takes no action.
*/
default public void contextDestroyed(ServletContextEvent sce) {}
}
代码举例:
ServletContextListenerA.java
package listener;
import javax.servlet.ServletContextListener;
public class ServletContextListenerA implements ServletContextListener {
@Override
public void contextInitialized(javax.servlet.ServletContextEvent sce) {
System.out.println("ServletContextListenerA被创建");
}
@Override
public void contextDestroyed(javax.servlet.ServletContextEvent sce) {
System.out.println("ServletContextListenerA已销毁");
}
}
配置 web.xml
启动服务器:
停止服务器:
小总结:
总的来说,ServletContextListener是Java Servlet API的一部分,它允许我们监听web应用的生命周期事件。我们可以通过实现这个接口来创建自己的监听器,并在web.xml中配置它,以便Tomcat知道它的存在。
ServletContextAttributeListener监听器:监听ServletContext中属性的添加、移除和修改
ServletContextAttributeListener本身也是一个接口,继承EventListener接口
相关方法:
方法名 |
作用 |
attributeAdded(ServletContextAttributeEvent scab) |
向ServletContext中添加属性时调用 |
attributeRemoved(ServletContextAttributeEvent scab) |
从ServletContext中移除属性时调用 |
attributeReplaced(ServletContextAttributeEvent scab) |
当ServletContext中的属性被修改时调用 |
ServletContextAttributeListener的源码:
package javax.servlet;
import java.util.EventListener;
public interface ServletContextAttributeListener extends EventListener {
/**
* Receives notification that an attribute has been added to the
* ServletContext.
*
* @param event the ServletContextAttributeEvent containing the
* ServletContext to which the attribute was added, along with the
* attribute name and value
*
* @implSpec
* The default implementation takes no action.
*/
default public void attributeAdded(ServletContextAttributeEvent event) {}
/**
* Receives notification that an attribute has been removed
* from the ServletContext.
*
* @param event the ServletContextAttributeEvent containing the
* ServletContext from which the attribute was removed, along with
* the attribute name and value
*
* @implSpec
* The default implementation takes no action.
*/
default public void attributeRemoved(ServletContextAttributeEvent event) {}
/*
* Receives notification that an attribute has been replaced
* in the ServletContext.
*
* @param event the ServletContextAttributeEvent containing the
* ServletContext in which the attribute was replaced, along with
* the attribute name and its old value
*
* @implSpec
* The default implementation takes no action.
*/
default public void attributeReplaced(ServletContextAttributeEvent event) {}
}
代码举例:
ServletContextAttributeListener01.java
package listener;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
public class ServletContextAttributeListener01 implements ServletContextAttributeListener {
@Override // 监听ServletContext添加属性
public void attributeAdded(ServletContextAttributeEvent sce) {
System.out.println("ServletContextAttributeListener01监听到了添加属性" +
sce.getName() + "的值");
}
@Override // 监听ServletContext移除属性
public void attributeRemoved(javax.servlet.ServletContextAttributeEvent sce) {
System.out.println("ServletContextAttributeListener01监听到了移除属性" +
sce.getName() + "的值");
}
@Override // 监听ServletContext替换属性
public void attributeReplaced(javax.servlet.ServletContextAttributeEvent sce) {
System.out.println("ServletContextAttributeListener01监听到了替换属性" +
sce.getName() + "的值");
}
}
ServletA.java
package servlet;
import javax.servlet.ServletContext;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/servletA") //这里servlet用的注解,不用在web.xml配置
public class ServletA extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp){
//给ServletContext添加属性
ServletContext servletContext = req.getServletContext();
servletContext.setAttribute("name", "Tom");
servletContext.setAttribute("name", "Jerry");
servletContext.removeAttribute("name");
System.out.println("ServletA处理完毕...");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp){
doPost(req, resp);
}
}
配置web.xml
启动服务器
除了ServletContextListener和ServletContextAttributeListener,其他的监听器用的比较少
作用:HttpSessionListener 是一个监听器,用来监听 HTTP 会话的创建和销毁。
当一个 HTTP 会话被创建或销毁时,它就会触发相应的事件,我们可以编写代码来响应这些事件。
例如,在会话创建时,我们可以进行一些初始化操作;在会话销毁时,我们可以释放一些资源。这样,我们就可以在用户的状态变化时,做出相应的处理。
HttpSessionListener的源码:
package javax.servlet.http;
import java.util.EventListener;
public interface HttpSessionListener extends EventListener {
/**
* Receives notification that a session has been created.
*
* @implSpec
* The default implementation takes no action.
*
* @param se the HttpSessionEvent containing the session
*/
default public void sessionCreated(HttpSessionEvent se) {}
/**
* Receives notification that a session is about to be invalidated.
*
* @implSpec
* The default implementation takes no action.
*
* @param se the HttpSessionEvent containing the session
*/
default public void sessionDestroyed(HttpSessionEvent se) {}
}
相关方法:
方法名 |
作用 |
sessionCreated(HttpSessionEvent se) |
创建session时调用 |
sessionDestroyed(HttpSessionEvent se) |
销毁session时调用 |
作用:HttpSessionAttributeListener 是一个用于监听 HTTP 会话属性变化的监听器。
这意味着,当会话中的属性发生添加、删除或修改时,这个监听器会接收到通知。
HttpSessionAttributeListener源码:
package javax.servlet.http;
import java.util.EventListener;
public interface HttpSessionAttributeListener extends EventListener {
/**
* Receives notification that an attribute has been added to a
* session.
*
* @param event the HttpSessionBindingEvent containing the session
* and the name and value of the attribute that was added
*/
default public void attributeAdded(HttpSessionBindingEvent event) {}
/**
* Receives notification that an attribute has been removed from a
* session.
*
* @param event the HttpSessionBindingEvent containing the session
* and the name and value of the attribute that was removed
*/
default public void attributeRemoved(HttpSessionBindingEvent event) {}
/**
* Receives notification that an attribute has been replaced in a
* session.
*
* @param event the HttpSessionBindingEvent containing the session
* and the name and (old) value of the attribute that was replaced
*/
default public void attributeReplaced(HttpSessionBindingEvent event) {}
}
相关方法:
方法名 |
作用 |
attributeAdded(HttpSessionBindingEvent event) |
向HttpSession添加属性时调用 |
attributeRemoved(HttpSessionBindingEvent event) |
向HttpSession移除属性时调用 |
attributeReplaced(HttpSessionBindingEvent event) |
向HttpSession替换属性时调用 |
作用:监听 Request 创建或销毁,即Request生命周期监听。
ServletRequestListener的源码:
package javax.servlet;
import java.util.EventListener;
public interface ServletRequestListener extends EventListener {
/**
* Receives notification that a ServletRequest is about to go out
* of scope of the web application.
*
* @param sre the ServletRequestEvent containing the ServletRequest
* and the ServletContext representing the web application
*
* @implSpec
* The default implementation takes no action.
*/
default public void requestDestroyed(ServletRequestEvent sre) {}
/**
* Receives notification that a ServletRequest is about to come
* into scope of the web application.
*
* @param sre the ServletRequestEvent containing the ServletRequest
* and the ServletContext representing the web application
*
* @implSpec
* The default implementation takes no action.
*/
default public void requestInitialized(ServletRequestEvent sre) {}
}
相关方法:
方法名 |
作用 |
requestDestroyed(ServletRequestEvent sre) |
创建request时调用 |
requestInitialized(ServletRequestEvent sre) |
销毁request时调用 |
作用:ServletRequestAttributeListener 监听器可以监听 ServletRequest 对象中的属性变化。当属性被添加、移除或替换时,这个监听器会收到通知并执行相应的操作。
ServletRequestAttributeListener 源码:
package javax.servlet;
import java.util.EventListener;
public interface ServletRequestAttributeListener extends EventListener {
/**
* Receives notification that an attribute has been added to the
* ServletRequest.
*
* @param srae the ServletRequestAttributeEvent containing the
* ServletRequest and the name and value of the attribute that was
* added
*
* @implSpec
* The default implementation takes no action.
*/
default public void attributeAdded(ServletRequestAttributeEvent srae) {}
/**
* Receives notification that an attribute has been removed from the
* ServletRequest.
*
* @param srae the ServletRequestAttributeEvent containing the
* ServletRequest and the name and value of the attribute that was
* removed
*
* @implSpec
* The default implementation takes no action.
*/
default public void attributeRemoved(ServletRequestAttributeEvent srae) {}
/**
* Receives notification that an attribute has been replaced on the
* ServletRequest.
*
* @param srae the ServletRequestAttributeEvent containing the
* ServletRequest and the name and (old) value of the attribute
* that was replaced
*
* @implSpec
* The default implementation takes no action.
*/
default public void attributeReplaced(ServletRequestAttributeEvent srae) {}
}
相关方法:
方法名 |
作用 |
attributeAdded(ServletRequestAttributeEvent srae) |
向Request添加属性时调用 |
attributeRemoved(ServletRequestAttributeEvent srae) |
向Request移除属性时调用 |
attributeReplaced(ServletRequestAttributeEvent srae) |
向Request替换属性时调用 |
HttpSessionBindingListener 监听器也叫session绑定监听器
作用:HttpSessionBindingListener 监听 HttpSession 中对象的添加和移除,以确保数据的准确性和一致性。它可以帮助我们跟踪数据变化并触发相应操作。
HttpSessionBindingListener 监听器用于监听某个对象在 HttpSession 中的添加和移除操作。当该对象被添加到 HttpSession 中或从 HttpSession 中移除时,监听器会自动执行相应的操作。这个监听器通常用于管理在 HttpSession 中存储的数据,确保数据的一致性和准确性。
简单来说,它可以帮助我们跟踪 HttpSession 中数据的变化,并触发相应的操作。
HttpSessionBindingListener源码:
package javax.servlet.http;
import java.util.EventListener;
public interface HttpSessionBindingListener extends EventListener {
/**
*
* Notifies the object that it is being bound to
* a session and identifies the session.
*
* @implSpec
* The default implementation takes no action.
*
* @param event the event that identifies the
* session
*
* @see #valueUnbound
*
*/
default public void valueBound(HttpSessionBindingEvent event) {}
/**
*
* Notifies the object that it is being unbound
* from a session and identifies the session.
*
* @implSpec
* The default implementation takes no action.
*
* @param event the event that identifies
* the session
*
* @see #valueBound
*
*/
default public void valueUnbound(HttpSessionBindingEvent event) {}
}
相关方法:
方法名 |
作用 |
valueBound(HttpSessionBindingEvent event) |
该类的实例被放到Session域中时调用 |
void valueUnbound(HttpSessionBindingEvent event) |
该类的实例从Session中移除时调用 |
HttpSessionActivationListener 监听器也叫钝化活化监听器
作用:HttpSessionActivationListener 监听 HttpSession 中对象的序列化和反序列化。在分布式系统中,它帮助处理对象的存储和恢复,允许在序列化和反序列化时执行特定操作。
HttpSessionActivationListener 的源码:
package javax.servlet.http;
import java.util.EventListener;
public interface HttpSessionActivationListener extends EventListener {
/**
* Notification that the session is about to be passivated.
*
* @implSpec
* The default implementation takes no action.
*
* @param se the {@link HttpSessionEvent} indicating the passivation
* of the session
*/
default public void sessionWillPassivate(HttpSessionEvent se) {}
/**
* Notification that the session has just been activated.
*
* @implSpec
* The default implementation takes no action.
*
* @param se the {@link HttpSessionEvent} indicating the activation
* of the session
*/
default public void sessionDidActivate(HttpSessionEvent se) {}
}
相关方法:
方法名 |
作用 |
sessionWillPassivate(HttpSessionEvent se) |
该类实例和Session一起钝化到硬盘时调用 |
sessionDidActivate(HttpSessionEvent se) |
该类实例和Session一起活化到内存时调用 |