首页 文章

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

提问于
浏览
43

我无法解决我的链接问题 . 你能帮忙解决这个问题,将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

请参阅此链接目录结构 .

enter image description here

8 回答

  • 7

    您的文件不在 jsp folder 之下,这就是找不到它的原因 . 你必须再回去1个文件夹试试这个:

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

    请注意失败的网址:

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

    现在检查一下你的链接:

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

    "../"是"The containing directory"或"Up one directory"的简写 . 这是一个 relative 网址 . 猜测,/ jsp / <somefolder> /中有一个文件,其中包含<link />和<style />元素 .

    我建议使用 absolute 网址:

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

    使用绝对URL的原因是我猜测链接包含在一些常见文件中 . 如果您尝试通过添加第二个“../”来更正相对路径,则可能会破坏/ jsp中包含的任何文件 .

  • 0

    如果您的资源具有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>
    
  • 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" />
    
  • 0

    请注意,如有必要,您可能需要停用广告拦截功能 . 如果您使用的是HTML页面,那么在Visual Studio中拖放脚本路径不起作用,但它适用于mvc,asp.netwebforms . 一小时后我想到了这个

  • 0

    请安装Ionic 3解决方案的应用程序脚本npm i -D -E @ ionic / app-scripts

  • 0

    <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

    我在startup.cs中添加了 app.UseStaticFiles(); 这个代码而不是修复它

相关问题