个性化阅读
专注于IT技术分析

解决问题:Failed to load resource the server responded with a status of 404 (Not Found)

CSS和JS链接出错:Failed to load resource: the server responded with a status of 404 (Not Found)。

CSS文件如下:

<link  href="../Jquery/jquery.multiselect.css" rel="stylesheet"/>
<link  href="../Jquery/style.css" rel="stylesheet" />
<link  href="../Jquery/prettify.css" rel="stylesheet" />

JS文件如下:

<script  src="../Jquery/jquery.multiselect.js"></script>
<script  src="../Jquery/prettify.js"></script>

CSS和JS链接出错,报错信息如下:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/RetailSmart/jsp/Jquery/jquery.multiselect.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/RetailSmart/jsp/Jquery/style.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/RetailSmart/jsp/Jquery/prettify.css
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/RetailSmart/jsp/Jquery/jquery.multiselect.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/RetailSmart/jsp/Jquery/prettify.js

解决办法:

1、如果HTML文件或JSP文件等和JS、CSS不在同一个文件,例如JSP文件夹和JS/CSS的文件夹同等,也就是说它们有相同的父文件夹,那么只需使用如下设置即可:

<script  src="../../Jquery/prettify.js"></script>

2、其它情况,可能HTML/JSP和JS/CSS文件夹不是同等的,那就需要做其他设置。以上的出错是因为路径的问题,“../“是”包含目录“或”向上一个目录“的简写,这是一个相对URL。除了使用上面的解决办法,你也可以在Web项目中直接使用绝对路径,该方式比较安全,路径从你的项目名开始如下:

<link href="/你的Web项目名/Jquery/jquery.multiselect.css" rel="stylesheet"/>
赞(1)
未经允许不得转载:srcmini » 解决问题:Failed to load resource the server responded with a status of 404 (Not Found)

评论 抢沙发

评论前必须登录!