When doing related operations about SpringMVC, this error often occurs. The following reasons will lead to this error
Warning: No Mapping Found for HTTP Request with Uri [/Myspring/web-inf/jsp/hello.jsp] in DispatcherServlet with name
Reason 1: In the web.xml
<servlet> <servlet-name>springDispatcherServlet</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> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
Note that if <url-Pattern>/</Url-Pattern> is written in/written as <url-Pattern>/*</url-Pattern>
<url-pattern>/</url-pattern> will match the path type URL such as /login, and it will not match the pattern as /*.jsp URL
< url-pattern>/*</url-pattern> will match all URLs: path -type and suffix URL (including /login, *.jsp, *.js,*.html, etc.), no matter how many layers of directory, it will be matched as:/view/ *JSP will also be matched.
Use <url-Pattern>/*</url-Pattern> You will find that this error will appear directly when you visit the JSP page, because this access request will also be intercepted by this service, and then the requested URI will not match HTTP Request The URI in the middle, because there is no such URI in HTTP Request.
Reason two: Handler class does not add @Controller Note
If the Handler class does not add @Controller annotations, the processor will not scan whether the class uses @RequestMapping annotations.
Reason three: It may be just the value of @RequestMapping is inconsistent with the request value of the page
, such as: There is a @RequestMapping (“/test”) page jump <a href=”/test”> test </a> and it should be <a href=”test”> test </a>
Reasons 4: When visiting static resources, there will also be this error
SpringMVC will also treat these requests for static resources as a common request, and then this request will be intercepted by DispatcherServlet interceptor, because the corresponding processor will cause errors.
Add <MVC: View-Controller Path = “/SUCCESS” View-name = “Success”/>/>/>/>
Configure <MVC: DEFAULT-Servlet-Handler/>
Note that Methods One or two also needs to add this tag: <MVC: Annotion-Driven> </mvc: Annotion-driven>, otherwise the ordinary requests that can be invalidated before.
<MVC: Default-Service-Handler/> Principles:
<MVC: Default-Servlet-Handler/> will define a defaultServelltpRequesthandler in the context of SpringMVC. It will screen for requests to enter DispatCherservlet. If you find that it is not mapping request, the request to the web application server is found to The default service processing, if it is not the request of static resources, it will be processed by DispatcherServlet
The name of the default service of the general web application server is default. If the default service name of the web server used is not a default, you need to specify
The name of the default service of the default service can be visited under TOMCAT \ Apache-Tomcat-8.5.24 \ Conf \ Web.xml file to view the configuration name of the defaultServlet.