Urlpatten configuration in Spring mvc web. xml, web. xmlurlpatten

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.