Filter过滤器

 

package com.example.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

@Component
public class DemoFilter implements Filter {
    private static final Logger logger = LoggerFactory.getLogger(DemoFilter.class);
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.info("=========DemoFilter=======init==============");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        logger.info("=========DemoFilter=======doFilter==start============");

        filterChain.doFilter(servletRequest,servletResponse);//执行过滤

        logger.info("=========DemoFilter=======doFilter==end============");
    }

    @Override
    public void destroy() {
        logger.info("=========DemoFilter=======destroy==============");
    }
}

 

上一篇:org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


下一篇:手写web服务器:实现简单filter逻辑