SpringMVC (9)_SpringMVC handles static resources

       Foreword: SpringMVC only needs to consider the problem of processing static resources when it intercepts all requests, that is, supports the REST style, because SpringMVC will map all URIs including static resources.

 

method one:

 

<!-- Access to static resources (js/image) -->
<!-- It only needs to be configured when SpringMVC intercepts all requests to prevent access to static resources from being intercepted. -->
<mvc:resources location="/js/image" mapping="/js/**"/>

 

 Method two:

<!--  
    * default-servlet-handler will define a DefaultServletHttpRequestHandler in the SpringMVC context,
    * It will screen the requests entering the DispatcherServlet, and if it finds that it is an unmapped request, it will pass the request to the default WEB application server
    * Servlet processing. If it is not a request for static resources, it will continue to be processed 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 explicitly specified through the default-servlet-name attribute
-->
<mvc:default-servlet-handler/>

 

Guess you like

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