SpringMVC configuration in web.xml

code show as below

  <servlet>
  	<servlet-name>springMVC</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  	<init-param>
  		<param-name>contextConfigLocation</param-name>
  		<param-value>classpath:springMVC.xml</param-value>
  	</init-param>
  </servlet>
  
  <servlet-mapping>
  	<servlet-name>springMVC</servlet-name>
  	<url-pattern>/</url-pattern>
  </servlet-mapping>

  It can be seen when configuring SpringMVC in web.xml, in fact, it is equipped with a servlet.

Then, in the <servlet-mapping> The <url-pattern> matching rule what is it?

url-pattern matching rules

<Url-pattern> of / in fact content from the full path name of the project after the start of match

比如http://localhost:8081/projectName/homepage/test.do  ,

/ * Match is /homepage/test.do this section

There are three, namely:

1. exact match

<url-pattern>/test/userList.action</url-pattern>

  An exact match is exactly precisely matched to the URL address

2. path match

<url-pattern>/</url-pattern>
<! - or ->
<url-pattern>/*</url-pattern>
<! - or ->
<url-pattern>/base/*</url-pattern>

  Among them, the difference between / and / * is

/ ==> will match the path type the URL , for example, / abc / test of this type of path

/ * ==> not only the path type matching URL, also matches the suffix type the URL , e.g. /abc/test.jsp

Therefore, if <url-pattren> only be set / *, then the return request (request to return generally /WEB-INF/view/XXX.jsp), will be the front end of the controller (the DispatcherServlet) intercept, to find lead less than the corresponding handler, 404 errors!

If you must use / * then can be used / XXX / * this method to avoid the return request interceptor

3. The extension matches

<url-pattern>*.do</url-pattern>
<url-pattern>*.action</url-pattern>
<Url-pattern> * </ url-pattern> // This is WRONG!
<! - more ->

  Intercepts and end with a * .do * .action request.

Matching order container

Container will first be an exact match, it could not find a route match, were also not found on the extension matches. Once the match is successful, do not match the lower side.

 Reference: https://blog.csdn.net/yzh18373476791/article/details/82719848

 

Guess you like

Origin www.cnblogs.com/jinyu59/p/11791998.html