springMVC handles static resource issues

Today, when writing the delete operation of springMVC RESTful CRUD, the get request is converted into a post request by js and finally converted into a delete request by the web.xml filter, the static resource js is intercepted

 

1. Why is there such a problem:
 elegant REST-style resource URLs do not want suffixes such as .html or .do
 If the DispatcherServlet request mapping is configured as /,
 Spring MVC will capture all requests from the WEB container, including static resources. request, SpringMVC will treat them as a normal request, because the corresponding handler cannot be found, it will cause an error.
 2. Solution: Configure <mvc:default-servlet-handler/> in the SpringMVC configuration file

 

default-servlet-handler will define a DefaultServletHttpRequestHandler in the SpringMVC context, which will screen the requests entering the DispatcherServlet. If it finds that it is an unmapped request, it will hand over the request to the default Servlet of the WEB application server for processing. If not DispatcherServlet continues to process requests for static resources. Generally, the default servlet name of the WEB application server is default. If the default servlet name of the WEB server used is not default, it needs to be explicitly specified through the default-servlet-name attribute.

 

After adding a new problem, the controller that was able to map successfully before now has a 404 error

 

Finally, configure <mvc:annotation-driven/> in the springMVC configuration file

 

The problem is solved, why should I add <mvc:annotation-driven/> I still don’t understand it clearly, I understand it will be added next time.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327039167&siteId=291194637