问答详情
源自:5-3 [Java Web] 过滤器的分类3

访问index.jsp页面之后过滤器执行了,但是并没有输出index.jsp中的内容

@WebFilter(filterName = "AsynFilter", value = {"/index.jsp"},dispatcherTypes={DispatcherType.REQUEST,DispatcherType.ASYNC})

public class AsynFilter implements Filter {


@Override

public void destroy() {

// TODO Auto-generated method stub


}


@Override

public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)

throws IOException, ServletException {

System.out.println("start…………AsynFilter");

arg2.doFilter(arg0,arg1); // 放行

System.out.println("end…………AsynFilter");

}


@Override

public void init(FilterConfig arg0) throws ServletException {

// TODO Auto-generated method stub


System.out.println("init…………AsynFilter");

}


}

访问index.jsp之后,不会输出index.jsp中的内容,但是会在控制台输出:

end…………AsynFilter

start…………AsynFilter

这是为什么?好像过滤器没有放行一样,不会执行index中的内容

提问者:一只丑橘 2017-11-12 17:12

个回答

  • qq_苏格兰有个洞_0
    2017-11-17 23:30:13
    已采纳

    因为访问index.jsp会立即跳至/servlet/AsynServlet路径,执行AsynFilter