When learning spring, when configuring Web. XML, configure Url-pattern AS/*, start the project to access your controller always reported 404. Check that a lot of discovery resources exist, the configured address is not a problem, why there are 404 errors. Finally found that their own configuration of the url-pattern wrong.
Now tidy up:
(1): When using SPRINGMVC, a dispatchservlet will be configured in Web. XML, as follows:
<!-- Spring MVC Servlet---
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</ Servlet-mapping>
(2): Configure the Spring configuration file
<!--default view parser is used when parsing errors above (HTML is used by default)--
<bean id= "defaultviewresolver"
class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "
p:order=" 2 ">
<property name=" Viewclass "
value=" Org.springframework.web.servlet.view.JstlView "/>
<property name=" ContentType " Value= "text/html"/>
<property name= "prefix" value= "/web-inf/jsp/"/>
<property name= "suffix" Value= ". jsp"/>
</bean>
(3): for example:
①:<url-pattern>/</url-pattern> matches a path URL such as/login, and does not match a suffix URL such as the *.jsp pattern
②:< Url-pattern>/*</url-pattern> matches all URLs: path-type and suffix-type URLs (including/login,*.jsp,*.js and *.html, etc.)
①: Address is Localhost:8088/login,/login returns login.jsp
Visit the/login under controller to jump to the corresponding view login.jsp
②: The address of the access is localhost:8088/login/,/login returns login.jsp
Access to the controller under the/login, jump to login.jsp, and then into the Dispatchservlet, because is/*, there will be localhost:8088/login/login.jsp to request controller , then a 404 error is reported if the controller does not have a/login/login.jsp mapping mapping.
(4): summary
< Url-pattern >/< Url-pattern >/* can match all request URLs, match to *.jsp, and return to the spring Dispatcherservlet class when the JSP view is returned. The corresponding controller is not found, so the 404 error is reported.
When the mapping rule is/*, the final return xx.jsp also through Dispatcherservlet, it will go to the corresponding processor, which is also the console printing nohandlerfound, also caused a 404 error, the page not want to see. When changed/, the servlet does not match the URI of the. JSP, and of course it will return to the page normally.
(5): reference article
Url-pattern the difference between/and/*
Difference between/and/* in servlet mapping URL pattern