【问题标题】:Css resource not available in jspcss资源在jsp中不可用
【发布时间】:2015-01-20 13:58:31
【问题描述】:

您好,我正在使用 spring,我想包含一个 css 文件。

我在webapp下创建了一个文件夹resources/mytheme/css/signing.css。

我的调度器 servlet 如下所示:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.springapp.mvc"/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <mvc:resources mapping="/resources/**" location="/resources/mytheme/" />

</beans>

在我的 jsp 文件中,我像这样引用 css 文件:

<link href="${pageContext.request.contextPath}/resources/css/signing.css" rel="stylesheet" >

当我浏览该页面时,我总是收到 404 并且请求的资源不可用。

谁能帮助我?

【问题讨论】:

  • 能否在您的 jsp 中包括如何引用您的 css?
  • 对不起,它没有包含在代码中,所以它没有显示出来。
  • 如果您转到:yourhost:8080/context/resources/css/signing.css,您看不到您的文件? jsp 生成正常,但没有 css?
  • 它没有显示任何东西。只是一个 404。
  • 但是你能访问你的jsp页面吗?

标签: html css spring jsp


【解决方案1】:

我通过将其添加到我的 web.xml 来解决问题

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/resources/*</url-pattern>
</servlet-mapping>

这使我的资源文件夹可用。

【讨论】:

    猜你喜欢
    • 2012-05-16
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-06
    相关资源
    最近更新 更多