【日常Exception】第七回:Failed to load resource: the server responded with a status of 404 (Not Found)
热门系列:
1.问题:
最近在重新整合SSM框架,然后view层返回的是html页面。而spring-mvc在过滤静态资源时,页面经常显示Failed to load resource: the server responded with a status of 404 (Not Found)这个错误。
2.解决方案:
<!-- DispatcherServlet不处理静态资源,交给服务器默认的servlet处理 -->
<mvc:default-servlet-handler />
<!-- 启用annotation -->
<mvc:annotation-driven />
<!--spring-mvc对静态资源的通过-->
<mvc:resources location="/resources/js/" mapping="/js/**" />
<mvc:resources location="/resources/css/" mapping="/css/**" />
<mvc:resources location="/resources/image/" mapping="/image/**" />
首先得如此配置。且js,css等静态文件必须放在webapp的resources目录下。否则即使换成resource目录名都不行,亲测过。而且不要放在WEB-INF下面,不然也访问不到。
本博客皆为学习、分享、探讨为本,欢迎各位朋友评论、点赞、收藏、关注,一起加油!
还没有评论,来说两句吧...