dispatherServlet拦截所有请求,但是不拦截JSP和其他配置的servelt

不是顺序问题,是就不拦截Servlet

不是load-on-startup启动先后顺序问题,是就是不拦截Servlet。

SpringMVC默认用的是第二个

//<url-pattern>/*</url-pattern>会拦截JSP,静态文件,不拦截Servlet,拦截陌生URL
//<url-pattern>/</url-pattern>拦截静态文件,不拦截JSP和Servlet,拦截陌生URL
public class MyDispatcherServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println(req.getRequestURI());
}
}

<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>servlet.MyDispatcherServlet</servlet-class>
<load-on-startup>-1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>JsonServlet</servlet-name>
<servlet-class>servlet.JsonServlet</servlet-class>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JsonServlet</servlet-name>
<url-pattern>/getJson</url-pattern>
</servlet-mapping>

 

posted on 2019-04-15 18:12  防空洞123  阅读(1160)  评论(0编辑  收藏  举报

导航