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

心已赠人 2022-05-26 07:50 240阅读 0赞

热门系列:

  • 程序人生,精彩抢先看


1.问题:

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


2.解决方案:

  1. <!-- DispatcherServlet不处理静态资源,交给服务器默认的servlet处理 -->
  2. <mvc:default-servlet-handler />
  3. <!-- 启用annotation -->
  4. <mvc:annotation-driven />
  5. <!--spring-mvc对静态资源的通过-->
  6. <mvc:resources location="/resources/js/" mapping="/js/**" />
  7. <mvc:resources location="/resources/css/" mapping="/css/**" />
  8. <mvc:resources location="/resources/image/" mapping="/image/**" />

首先得如此配置。且js,css等静态文件必须放在webapp的resources目录下。否则即使换成resource目录名都不行,亲测过。而且不要放在WEB-INF下面,不然也访问不到。

本博客皆为学习、分享、探讨为本,欢迎各位朋友评论、点赞、收藏、关注,一起加油!

20201029165124734.gif

发表评论

表情:
评论列表 (有 0 条评论,240人围观)

还没有评论,来说两句吧...

相关阅读