加载静态资源(css/js等)遇到的错误
Failed to load resource: the server responded with a status of 404 ()
GET http://localhost:8080/static/js/jquery-3.3.1.min.js net::ERR_ABORTED 404
解决方案
1 解决方法(isELIgnored="false"
)
出现问题的片段为:
<script src="${pageContext.request.contextPath }/static/js/jquery-3.3.1.min.js"></script>
加入isELIgnored="false"
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
然后重启服务器看看会不会还报这个错
2 解决方法(检查springmvc.xml配置/是否存在静态资源拦截)
若使用SSM框架,请检查:
-
springmvc.xml
是否正常加载? -
springmvc.xml
加载了使用漏写<mvc:resources>
对静态资源服务。具体做法参考How to use CSS, JavaScript and Images in Spring MVC | Java Web Tutor
3 解决方法(IDEA out目录是否存对应静态资源)
对于使用了IDEA的朋友,请检查是否out
目录是否存在对应的js、css等静态文件。
若没有,请打开Project Structure
,添加静态文件所在目录到Artifacts
-> Output Layout
中的<output root>
下。
我目前的添加的static文件夹,因此我要添加static到<output root>
做法如下:
重启TOMCAT即可。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。