使用eclipse编写error,为什么跳转不到编写的error.jsp页面,仍然是404
<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>FirstFilter</filter-name> <filter-class>com.imooc.filter.FirstFilter</filter-class> </filter><filter-mapping> <filter-name>FirstFilter</filter-name> <url-pattern>/index.jsp</url-pattern></filter-mapping> <!-- <filter-mapping> <filter-name>FirstFilter</filter-name> <url-pattern>/main.jsp</url-pattern> <dispatcher>FORWARD</dispatcher></filter-mapping> --> <!-- <filter> <filter-name>SecondFilter</filter-name> <filter-class>com.imooc.filter.SecondFilter</filter-class></filter> <filter-mapping> <filter-name>SecondFilter</filter-name> <url-pattern>/index.jsp</url-pattern></filter-mapping> --> <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page> </web-app>
package com.imooc.filter; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class FirstFilter implements Filter { @Override public void destroy() { System.out.println("destory-----FirstFilter"); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("start---FirstFilter--doFilter"); // chain.doFilter(request, response); HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse response2 = (HttpServletResponse) response; //重定向 response2.sendRedirect(req.getContextPath()+"/main.jsp"); //转发 // req.getRequestDispatcher("main.jsp").forward(request, response); // req.getRequestDispatcher("main.jsp").include(request, response); System.out.println("end---FirstFilter--doFilter"); } @Override public void init(FilterConfig filterConfig) throws ServletException { System.out.println("init-----FirstFilter"); } }
以上分别是web.xml和FirstFilter的代码,请大神告知下