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

bartex9

我正在开发一个小的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>

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>

预先感谢您的帮助!

诺伯特·范·诺贝尔

为了能够访问资源而无需通过完整的侦听器逻辑,您需要在您的添加1条配置行dispatcher-servlet.xml

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

该行注意/resources不要解析该位置下的所有调用文件,并且浏览器可以在预期的URL上直接访问这些文件

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Spring MVC + Tiles + Spring Security =请求的资源不可用

来自分类Dev

请求的资源在Spring MVC中不可用

来自分类Dev

Tomcat和STS上的Spring Web MVC-请求的资源不可用

来自分类Dev

Spring MVC中的重定向错误(http状态404请求的资源不可用jsp)

来自分类Dev

CSS资源在JSP中不可用

来自分类Dev

CSS文件-> http状态404-请求的资源不可用

来自分类Dev

请求的资源不可用?

来自分类Dev

grails Webflow请求的资源不可用

来自分类Dev

请求的资源不可用错误

来自分类Dev

描述所请求的资源不可用

来自分类Dev

CSS属性不可用

来自分类Dev

Spring Security 自定义登录表单重定向到资源不可用

来自分类Dev

资源不可用

来自分类Dev

反应导入的 css 不可用

来自分类Dev

在MVC上向用户显示不可用的页面

来自分类Dev

Tomcat Servlet:错误404-请求的资源不可用

来自分类Dev

Http状态404-/请求的资源不可用

来自分类Dev

HTTP状态404请求的资源不可用

来自分类Dev

所请求的资源不可用Glassfish 4

来自分类Dev

404请求的资源不可用Eclipse / Tomcat

来自分类Dev

Java Servlet,http状态404,请求的资源不可用

来自分类Dev

所请求的资源[项目名称/ servlet]不可用

来自分类Dev

请求的资源不可用。Apache Tomcat / 7.0.42

来自分类Dev

所请求的资源在REST中不可用

来自分类Dev

Apache Tomcat错误:请求的资源不可用

来自分类Dev

所请求的资源不可用于缺省jsp的输入

来自分类Dev

Tomcat servlet所请求的资源不可用

来自分类Dev

请求的资源不可用。Servlet到JSP

来自分类Dev

所请求的资源不可用Glassfish 4