In a servlet mapping in Spring MVC how do I map the root of a url pattern directory?

后端 未结 5 1504
故里飘歌
故里飘歌 2020-12-05 16:28

    testServlet
    /test/*

<         


        
5条回答
  •  暖寄归人
    2020-12-05 17:04

    First of all, the difference between mapping dispatcher servlet to "/" and to "/*". There is a difference!

    When mapping to "/*", all URL requests (including something like this "/WEB-INF/jsp/.../index.jsp") are mapped to dispatcher servlet.

    Secondly, when using Spring + Tiles, and returning some JSP in your tiles definition, it is treated as an internal forward request, and handled by the same servlet as the original request. In my example, I invoke root URL "/", which is properly caught by home() method, and then forwarded to "index.jsp" by Tiles, which is again being handled by Dispatcher Servlet. Obviously, dispatcher servlet cannot handle "index.jsp", because there is no controller for it.

    Yeah, it is ugly, but looks like this is the way it works.

    So, the only solution I've found so far: to change "/*" back to "/" in web.xml. This way JSPs are rendered properly by Tomcat's jsp servlet, I guess, and not dispatcher servlet. Unfortunately, this fix will break the ROOT URL dispatching by Spring, so you need to leave the idea of using ROOT URL + Tiles for now.

    Please note that adding explicit servlet mapping ".jsp -> Tomcat jsp in web.xml doesn't help, when using "/*", and it sucks.

    Still the problem is not resolved.

    Also this is the problem in Spring MVC 3.0

提交回复
热议问题