SpringMVC中可能存在错误:无法处理像/或/ *这样的servlet路径

时间:2014-09-21 04:31:10

标签: spring spring-mvc

我想我在Spring MVC中发现了一个错误,如果web xml中的servlet路径仅仅是' /'那么JstlView就不起作用了。或者' / *'没有单引号。您可以自己尝试,使用基于spring MVC的任何可用的Web应用程序,然后调整调度程序servlet路径以匹配' /'或者' / *',然后访问该页面(当然使用新的正确网址),您会收到400错误。

这是我的例子,我有一个spring mvc app,这是在web xml:

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/mvc/*</url-pattern>
</servlet-mapping>

我部署并访问:

http://localhost:8080/contextroot/mvc/template

页面看起来非常好,这是日志:

21:24:05.024 [http-bio-8080-exec-92] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /template
21:24:05.048 [http-bio-8080-exec-92] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Returning handler method [public java.lang.String com.project.www.controller.ResultController.getPersonList(org.springframework.ui.ModelMap)]
21:24:05.050 [http-bio-8080-exec-92] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'resultController'
21:24:05.056 [http-bio-8080-exec-92] DEBUG o.s.web.servlet.DispatcherServlet - Last-Modified value for [/contextroot/mvc/template] is: -1
21:24:05.104 [http-bio-8080-exec-92] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'template'
21:24:05.106 [http-bio-8080-exec-92] DEBUG o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'template'; URL [/WEB-INF/jsp/template.jsp]] in DispatcherServlet with name 'dispatcher'
21:24:05.124 [http-bio-8080-exec-92] DEBUG o.s.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/jsp/template.jsp] in InternalResourceView 'template'
21:24:05.695 [http-bio-8080-exec-92] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request

所以这一切都在这一行之上,但现在我改变了web xml:

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

我重新部署并访问:

http://localhost:8080/contextroot/template

但我得到400错误,这是日志:

21:09:11.365 [http-bio-8080-exec-78] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/contextroot/template]
21:09:11.372 [http-bio-8080-exec-78] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /template
21:09:11.383 [http-bio-8080-exec-78] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Returning handler method [public java.lang.String com.AnnaUnivResults.www.controller.ResultController.getPersonList(org.springframework.ui.ModelMap)]
21:09:11.384 [http-bio-8080-exec-78] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'resultController'
21:09:11.387 [http-bio-8080-exec-78] DEBUG o.s.web.servlet.DispatcherServlet - Last-Modified value for [/contextroot/template] is: -1
21:09:11.437 [http-bio-8080-exec-78] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'template'
21:09:11.440 [http-bio-8080-exec-78] DEBUG o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'template'; URL [/WEB-INF/jsp/template.jsp]] in DispatcherServlet with name 'dispatcher'
21:09:11.455 [http-bio-8080-exec-78] DEBUG o.s.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/jsp/template.jsp] in InternalResourceView 'template'
21:09:11.456 [http-bio-8080-exec-78] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/contextroot/WEB-INF/jsp/template.jsp]
21:09:11.457 [http-bio-8080-exec-78] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /WEB-INF/jsp/template.jsp
21:09:11.459 [http-bio-8080-exec-78] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/WEB-INF/jsp/template.jsp]
21:09:11.460 [http-bio-8080-exec-78] WARN  o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/contextroot/WEB-INF/jsp/template.jsp] in DispatcherServlet with name 'dispatcher'
21:09:11.461 [http-bio-8080-exec-78] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
21:09:11.464 [http-bio-8080-exec-78] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request

我很确定这是春天的一个错误。我想在春天的网站上发布这个帖子,但显然春天的问题页面只会把你送到StackOverflow,如果你问我就有点欺骗。

我想我的问题是,这是一个错误吗?

1 个答案:

答案 0 :(得分:0)

将/ *更改为/

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <!--url-pattern>/*</url-pattern-->
    <url-pattern>/</url-pattern>
</servlet-mapping>