iyuks
2021-07-15 11:26
采纳率: 94.8%
浏览 180
已结题

web.xml文件 配置了过滤器,为什么不起作用呢?

    <filter>
        <filter-name>filter1</filter-name>
        <filter-class>com.yu.configure.filter.CustomFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>filter1</filter-name>
        <url-pattern>/</url-pattern>
    </filter-mapping>


public class CustomFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setAttribute("filter1", "CustomFilter");
        chain.doFilter(request, response);
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("filter1"+filterConfig);
    }

    @Override
    public void destroy() {

    }
}

2条回答 默认 最新

相关推荐 更多相似问题