Spring MVC configure url-pattern

后端 未结 1 1144
盖世英雄少女心
盖世英雄少女心 2020-12-19 12:38


I try to configure simple Controller.

I have:
in web.xml


    mvc-dispatcher&l         


        
相关标签:
1条回答
  • 2020-12-19 13:21

    Spring is working with the information how the servlet mapping is defined. If you are using suffix mapping (*.something), then Spring uses just the first part (without the suffix). This means you shuold map just /index in your url-pattern (without the suffix).

    JavaDoc in Spring's UrlPathHelper#getPathWithinServletMapping gives a better description what is being used in the mapping process:

    Return the path within the servlet mapping for the given request, i.e. the part of the request's URL beyond the part that called the servlet, or "" if the whole URL has been used to identify the servlet.

    Detects include request URL if called within a RequestDispatcher include.

    E.g.: servlet mapping = "/test/*"; request URI = "/test/a" -> "/a".

    E.g.: servlet mapping = "/test"; request URI = "/test" -> "".

    E.g.: servlet mapping = "/*.test"; request URI = "/a.test" -> "".

    0 讨论(0)
提交回复
热议问题