SpringMVC 14. Handling static resources

Handling static resources

Elegant RESTful resource URLs don't want suffixes like .html or .do

If the DispatcherServlet request mapping is configured as /, Spring MVC will capture all requests from the WEB container, including requests for static resources, and Spring MVC will treat them as a normal request, and an error will result if the corresponding handler cannot be found.

<mvc:default-servlethandler/>The problem of static resources can be solved by configuring in the SpringMVC configuration file :

  • <mvc:default-servlet-handler/>A DefaultServletHttpRequestHandler will be defined in the SpringMVC context, which will screen the requests entering the DispatcherServlet. If it is found to be an unmapped request, the request will be processed by the default Servlet of the WEB application server. If it is not a request for static resources, Continue processing by DispatcherServlet
  • Generally, the name of the default servlet of the WEB application server is default. If the default servlet name of the WEB server used is not default, it needs to be specified explicitly through the defaultservlet-name attribute.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325528291&siteId=291194637