當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring MVC访问不到静态资源
生活随笔
收集整理的這篇文章主要介紹了
Spring MVC访问不到静态资源
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
運行Spring MVC項目,發現.css,js等文件加載不了,一般是spring MVC的攔截匹配導致的。
例如我在web.xml里這樣配置:
于是所有請求都會被攔截,包括靜態資源。所以,要配置靜態資源不經過Spring MVC。在spring-servlet.xml(Spring MVC配置文件)里增加配置如下即可:
<!-- 配置靜態資源的路徑 --> <mvc:resources location="/resource/" mapping="/resource/**"></mvc:resources><mvc:resources location="/css/" mapping="/css/**"></mvc:resources><mvc:resources location="/image/" mapping="/image/**"></mvc:resources><mvc:resources location="/js/" mapping="/js/**"></mvc:resources>總結
以上是生活随笔為你收集整理的Spring MVC访问不到静态资源的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在webpack中使用eslint配置(
- 下一篇: Spring MVC 测试 | 模拟提交