Filter
概念
快速入门
执行流程
package com.itheima.web.filter;
import javax.servlet.*;
import javax.servlet.annotation.*;
import java.io.IOException;
@WebFilter("/*")
public class FilterDemo implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
// 先执行放行前的,放行前对request数据进行处理
System.out.println("1. FilterDemo...");
// 放行
chain.doFilter(request, response);
// 这是放行后的代码,放行后,对Response 数据进行处理
System.out.println("3. FilterDemo...");
}
public void init(FilterConfig config) throws ServletException {
}
public void destroy() {
}
}