问题:failed to load resource: the server responded with a status of 404 (not found)
打开html页面css样式,js脚本以及图片无法加载,检查源码的时候出现如上错误
解决方案:在Springmvc.xml配置文件中添加如下代码
<!-- 静态资源的配置 -->
<mvc:annotation-driven/>
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/images/" mapping="/images/**"/>
<mvc:resources location="/fonts/" mapping="/fonts/**"/>
根本原因:在web.xml文件中在进行servlet-mapping的配置时url-pattern设置的是"/"
这就意味着所有请求都会被映射到dispatcher-servlet中 为了能够直接访问态资源就必须在springmvc.xml文件中进行如上的配置