Filter 表示过滤器,是 JavaWeb 三大组件(Servlet、Filter、Listener)之一
package com.stdu.web.filter;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
@WebFilter("/*")
public class Filter_demo implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//1.放行前对request数据进行处理
System.out.println("1.过滤器执行了");
filterChain.doFilter(servletRequest,servletResponse);
//2.放行后对response数据进行处理
System.out.println("3.过滤器执行了");
}
@Override
public void destroy() {
}
}
标签:2024,31,Filter,过滤器,void,Override,import,public
From: https://www.cnblogs.com/XYu1230/p/18518120