【问题标题】:JSP not picking up CSS fileJSP没有拾取CSS文件
【发布时间】:2018-01-26 13:57:16
【问题描述】:

我使用 Spring 在 Eclipse Mars 中创建了一个简单的动态 Web 项目。我的 JSP 指的是 CSS 文件,但 css 文件没有被拾取。

Eclipse 项目文件夹结构: enter image description here

这是怎么做的,我在我的 JSP 中引用它:

【问题讨论】:

  • href="/css/anotherStylesheet.css"

标签: css eclipse jsp


【解决方案1】:

我的项目结构和你的一样,我通过以下方式引用 css 文件:

href="css/anotherStylesheet.css"

【讨论】:

    【解决方案2】:

    用它来添加css文件

    <link href="folder/styleFile.css" rel="stylesheet" type="text/css" />
    

    当您将 CSS 文件直接拖放到您的页面时,它也可能会起作用。

    【讨论】:

    • 谢谢!我真的很感谢你的帮助!我尝试了两种方法,它没有工作。我第一次得到:“警告:在 DispatcherServlet 中找不到带有 URI [/FirstSpringMVCPrj/css/anotherStylesheet.css] 的 HTTP 请求的映射,名称为 'FirstSpringMVCPrj'”第二次(当我拖放时):警告:找不到映射URI [/FirstSpringMVCPrj/WebContent/css/anotherStylesheet.css] 在 DispatcherServlet 中的 HTTP 请求,名称为“FirstSpringMVCPrj”
    • 首先您需要在 dispatcher-servlet 文件中声明您的资源,如下所示:&lt;mvc:resources mapping="/resources/**" location="/resources/folder/" /&gt; 任何带有 url 映射 /resources/** 的请求都将直接查找 /resources/folder/。现在在 jsp 文件中,您需要像这样包含您的 css 文件:&lt;link href="&lt;c:url value="/resources/css/main.css" /&gt;" rel="stylesheet"&gt; 同样,您可以包含 js 文件。
    【解决方案3】:

    配置 spring.xml 并在配置中添加 css 文件夹。同时检查 eclipse 部署程序集(包括你的 webcontent 目录)

    【讨论】:

      猜你喜欢
      • 2018-12-01
      • 2013-06-23
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2013-01-23
      • 1970-01-01
      相关资源
      最近更新 更多