资源加载失败:服务器响应状态为404(未找到)

108

我无法解决我的链接问题。你能帮我解决如何链接CSS和JS文件吗?

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>

错误:

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

请参考这个链接目录结构。

在此输入图片描述


现在它已经按照他的回答正常工作了 @Geddemet - user3331535
请通过投票箭头旁边的绿色复选框接受他的答案。 - Nicholas Hazel
我建议您在这里检查此问题:http://magento.stackexchange.com/questions/96032/magento-2-installation-issue-404-error-while-trying-to-load-admin-page - Mohammad nasim
13个回答

93

您的文件不在jsp文件夹下,所以找不到。 您需要再返回1个文件夹。 请尝试以下方法:

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

我之前遇到了一个字体的问题,但现在已经解决了。 :) - Mehedi_Sharif
我遇到了一个错误 - "无法加载资源:服务器响应404(未找到)"。这个解决方案对我有用。 - anoynmous
我的路径是正确的,但仍会出现此错误: undefined:1 GET http://localhost/e-commerce/undefined 404(未找到) - Inês Barata Feio Borges

19

请注意失败的URL:

Failed ... http://localhost:8080/RetailSmart/jsp/Jquery/jquery.multiselect.css

现在检查你的一个链接:

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

"../"是指“包含目录”或“上一级目录”的简写形式。这是一个相对URL。猜测您在/jsp//中有一个文件,其中包含和


7
如果您有扩展名为woff的资源并且出现错误,则在您的web.config应用程序中添加以下代码可以帮助解决问题。
<system.webServer>
<staticContent>
   <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
</staticContent>
</system.webServer>

如果找不到JavaScript或CSS等资源,则按以下方式提供添加链接或脚本的路径。
<link ref="@(Url.Content("path of css"))" rel="stylesheet">

<script src="@(Url.Content("path of js"))" type="text/javascript"></script>

1
我正在使用Asp.net。我按照说明编辑了我的web.config文件,然后开始出现500错误。 - Monir Tarabishi
错误状态500与资源未找到有关...请检查您缺少哪些资源... - Prasad Joshi
您还可以查看https://dev59.com/QW435IYBdhLWcg3wfQJ9。 - Prasad Joshi
我得到了字体文件的错误,而不是整个页面的错误。 - Monir Tarabishi

5
将以下内容添加到您的配置文件中。然后将所有资源(例如img,css,js等)放入src > main > webapp > resources目录中。
public class Config extends WebMvcConfigurerAdapter{
   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {  
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
   }
}

之后,您可以像这样访问您的资源。
<link href="${pageContext.request.contextPath}/resources/assets/css/demo.css" rel="stylesheet" />

4
如果您的URL是:
http://127.0.0.1:8080/binding/

请在index.html中更新以下属性:

<base href="/binding/">

简而言之,您需要检查文件的位置。

3

<system.webServer>中的web.config文件中添加以下代码(<handler>):

<system.webServer>
<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>

3
如果您正在从相同文件夹加载js,请使用正斜杠。
<script src="bundle.js"></script> 

替换为

<script src="/bundle.js"></script>

1

我在我的startup.cs中添加了app.UseStaticFiles();这段代码,然后问题得到了解决。


1
我遇到了同样的问题,这是因为我从服务器返回图像到一个组件,而这个组件在路径中只有1步。这就是我的意思。请参见文件排列。
*projectfolder/phpfiles/component.php*

现在我的图片文件夹位于这里 projectfolder/images/ 现在我通过添加../来修复它,以便可以向后跳过1步
祝你好运

0

请注意,如果需要,您可能需要禁用广告拦截器。 如果您正在使用HTML页面,则Visual Studio中的拖放脚本路径不起作用,但对于MVC和ASP.NET Web Forms则有效。 我在一个小时后弄清了这一点。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接