Spring MVC配置url-pattern

我尝试配置简单的控制器。

我有:
web.xml中

 mvc-dispatcher org.springframework.web.servlet.DispatcherServlet 1   mvc-dispatcher /index.jsp  

mvc-dispatcher-servlet.xml中

   /jsp/   .jsp             

这是我的控制器

 public class TBController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { System.out.println("It is here"); ModelAndView model = new ModelAndView("index"); return model; }} 

我在Tomcat 6上运行,在这个配置中它(/index.jsp)运行完美!

但如果我像这样更改url-pattern

  mvc-dispatcher *.jsp  

它返回404访问/index.jsp

我在控制台中看到“它在这里”,这意味着url-pattern工作正常,但ModelAndView没有初始化

奇怪的是,看起来他试图访问空资源(Chrome让我发现“HTTP状态404 – ”)

请帮助我了解发生了什么..可能是我错过了url-pattern规范中的一些内容?

UPD:
感谢Pavel Horal,已找到解决方案。
我刚用web.xml替换了我的url-pattern

 /test/* 

现在它通过/test/index.jsp响应

Spring正在处理如何定义servlet映射的信息。 如果您使用后缀映射( *.something ),则Spring仅使用第一部分(不带后缀)。 这意味着你在你的url-pattern中没有映射just /index (没有后缀)。

Spring的UrlPathHelper#getPathWithinServletMapping JavaDoc UrlPathHelper#getPathWithinServletMapping可以更好地描述映射过程中使用的内容:

返回给定请求的servlet映射中的路径,即请求URL的一部分超出调用servlet的部分,如果整个URL已用于标识servlet,则返回“”。

如果在RequestDispatcher include中调用,则检测包括请求URL。

例如:servlet mapping =“/ test / *”; 请求URI =“/ test / a” – >“/ a”。

例如:servlet mapping =“/ test”; 请求URI =“/ test” – >“”。

例如:servlet mapping =“/ *。test”; 请求URI =“/ a.test” – >“”。