Reason: DispatcherServlet cause the client can not access any static resources directly
method one:
Using <MVC: Resources /> , for example:
- In the Spring-web.xml configuration file configuration, so the deal with static resources returned to the Web application server process via the Spring MVC framework , can achieve the purpose of access to static resources.
<mvc:resources location="/img/" mapping="/img/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/css/" mapping="/css/**"/>
Method Two:**
采用 < mvc:default-servlet-handler></mvc:default-servlet-handler>
- In the Spring-web.xml configuration file configuration:
<mvc:default-servlet-handler></mvc:default-servlet-handler>
- If the request is a static resource, it forwards the request from the default Web server Servlet application process , if not static resource request before continuing to process the DispatcherServlet.
- The default Servlet is default, so configure the default Servlet in web.xml under WEB-INF years
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/assets/*</url-pattern>
<url-pattern>/js/*</url-pattern>
<url-pattern>/vendor/*</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.jpg</url-pattern>
<url-pattern>*.gif</url-pattern>
<url-pattern>*.png</url-pattern>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
- Static resources url-pattern inside can be accessed directly