Urlpatten configuration in Spring mvc web. xml, web. xmlurlpatten
When spring mvc is used, we will configure spring's DispatcherServlet as the request forwarder.
<servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern></servlet-mapping>
Here, url-pattern is used to set the Request Path mode that can be processed. One problem I encountered is that when I set url-pattern to/*, my requests always report
HTTP Status 404-error.
My Controller is also accessed in the background, but the page I specified cannot be found when I returned the ModeAndView.
Ffffffff September 29 11:19:31 org. springframework. web. servlet. pageNotFound noHandlerFound warning: No mapping found for HTTP request with URI [/SpringMvcDemo/WEB-INF/jsp/hello. jsp] in DispatcherServlet with name 'spring'
Fffffff is the output of my request to the controller. Hello is the name of the set view. The hello. jsp file exists in my WEB-INFO/jsp directory.
Check the network to find the problem:
It turns out that the key lies in the url-pattern setting: when it is <url-pattern>/</url-pattern>, it will match a path url like/hello, the mode is *. when a suffix-type url such as jsp is <url-pattern>/* </url-pattern>, all URLs are matched: url of the path and url of the suffix type (including/hello ,*. jsp ,*. js and *. html, etc)
Therefore, it is OK to change.