内部转发为什么没有执行dofilter()方法
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("start----doFilter--FirstFilter");
//chain.doFilter(request, response);
HttpServletRequest req =(HttpServletRequest) request;
HttpServletResponse response2 =(HttpServletResponse) response;
//重定向
// response2.sendRedirect(req.getContextPath()+"/index.jsp");
//转发
req.getRequestDispatcher("index.jsp").forward(request, response);
// req.getRequestDispatcher("main.jsp").include(request, response);
System.out.println("end------doFilter--FirstFilter");
}
配置文件:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>Filter</filter-name>
<filter-class>FirstFilter.firstFilter</filter-class>
</filter>
<!--
<filter-mapping>
<filter-name>Filter</filter-name>
<url-pattern>/index.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
-->
<filter-mapping>
<filter-name>Filter</filter-name>
<url-pattern>/index.jsp</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>
控制台执行了init() 但是执行index.jsp并没有打印dofilter方法