經過RequestMapping(“xx”)后 轉發請求時會在url里面附帶地址,
導致訪問靜態資源文件失敗,
解決辦法是在 spring-mvc.xml文件中加上
<mvc:default-servlet-handler/>
<!-- 由於在web.xml中定義的url攔截形式為“/”表示攔截所有的url請求,
包括靜態資源例如css、js等。所以需要在springmvc.xml中添加資源映射標 -->
<mvc:resources location="/static/js/" mapping="/*/static/js/**"/>
<mvc:resources location="/static/css/" mapping="/*/static/css/**"/>
<mvc:resources location="/static/fonts/" mapping="/*/static/fonts/**"/>
<mvc:resources location="/static/images/" mapping="/*/static/images/**"/>
<mvc:resources location="/static/lib/" mapping="/*/static/lib/**"/>
以及在web.xml里加上
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>