csp资源在jsp中不可用

时间:2021-04-06 16:54:57

Hi I'm using spring and I want to include a css file.

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

I've created a folder resources/mytheme/css/signing.css under webapp.

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

My dispatcher servlet looks like this:

我的调度程序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>

In my jsp file I reference to the css file like this:

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

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

When I surf to the page I always get a 404 and The requested resource is not available.

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

Someone who can help me?

有人可以帮帮我吗?

1 个解决方案

#1


0  

I fixed the problem by adding this to my web.xml

我通过将此问题添加到我的web.xml来解决了这个问题

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

This makes my resource folder available.

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

#1


0  

I fixed the problem by adding this to my web.xml

我通过将此问题添加到我的web.xml来解决了这个问题

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

This makes my resource folder available.

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