Filter -2024/10/31

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() {

    }
}

posted @ 2024-10-31 17:32  XYu1230  阅读(3)  评论(0编辑  收藏  举报