Java 带CSS的Spring MVC-请求的资源不可用

Java 带CSS的Spring MVC-请求的资源不可用,java,spring,spring-mvc,Java,Spring,Spring Mvc,我正在开发一个小型Spring应用程序。我在将CSS文件添加到.jsp网页时遇到问题。我收到Glassfish的403错误-请求的资源不可用 以下是项目结构: webapp --WEB-INF --jsp --resources --css 这是我的.jsp代码: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@page contentType="text/html

我正在开发一个小型Spring应用程序。我在将CSS文件添加到.jsp网页时遇到问题。我收到Glassfish的403错误-请求的资源不可用

以下是项目结构:

webapp
  --WEB-INF
    --jsp
  --resources
    --css
这是我的.jsp代码:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="resources/css/style.css" rel="stylesheet" type="text/css">
        <title>Title</title>
    </head>

    <body>
    </body>
</html>

标题
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Spring Security -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml, /WEB-INF/spring-security.xml</param-value>
    </context-param>

    <filter>  
        <filter-name>springSecurityFilterChain</filter-name>  
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  
    </filter>  

    <filter-mapping>  
        <filter-name>springSecurityFilterChain</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>
</web-app>

调度员
org.springframework.web.servlet.DispatcherServlet
1.
调度员
/
org.springframework.web.context.ContextLoaderListener
上下文配置位置
/WEB-INF/applicationContext.xml,/WEB-INF/spring-security.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*  
dispatcher-servlet.xml

<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />


    <context:component-scan base-package="service, controller" />


    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"/>

</beans>


提前谢谢你的帮助

为了能够访问资源而不必经过完整的侦听器逻辑,您需要向
dispatcher servlet.xml添加一行配置:

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


这一行注意到
/resources
位置下所有被调用的文件都不会被解析,可以通过预期url上的浏览器直接访问。

好的,我现在可以访问我的
style.css
,但我的所有资源都不见了<代码>在名为“dispatcher”的DispatcherServlet中,找不到URI为[/MyAPP/login]的HTTP请求的映射。
此时只是猜测,因为这可能有多种原因:
在为bean使用注释时不存在,和
:我希望得到完整的包名。将
添加到
dispatcher servlet.xml
解决了这个问题。谢谢