日常Exception(七):Failed to load resource: the server responded with a status of 404 (Not Found)

最近在重新整合SSM框架,然后view层返回的是html页面。而spring-mvc在过滤静态资源时,页面经常显示Failed to load resource: the server responded with a status of 404 (Not Found)这个错误。


解决方案:1.

<!-- 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下面,也访问不到。

发布了43 篇原创文章 · 获赞 39 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/yy339452689/article/details/80111438