Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我能';是否无法访问此Spring MVC应用程序的\webapp\resources\文件夹中定义的CSS资源?_Spring_Spring Mvc_Resources_Freemarker - Fatal编程技术网

为什么我能';是否无法访问此Spring MVC应用程序的\webapp\resources\文件夹中定义的CSS资源?

为什么我能';是否无法访问此Spring MVC应用程序的\webapp\resources\文件夹中定义的CSS资源?,spring,spring-mvc,resources,freemarker,Spring,Spring Mvc,Resources,Freemarker,我是SpringMVC的新手,在使用FreeMarker进行视图的SpringMVC项目中,我遇到了以下问题 我在尝试导入某些资源时发现一些问题(CSS文件和图像定义在我的项目的myProject\src\main\webapp\resources\目录中) 因此,我有一个header.ftl文件,它代表我所有页面的页眉: <!DOCTYPE html> <!--[if IE 8]><html class="no-js is-ie8"><![endif]

我是SpringMVC的新手,在使用FreeMarker进行视图的SpringMVC项目中,我遇到了以下问题

我在尝试导入某些资源时发现一些问题(CSS文件和图像定义在我的项目的
myProject\src\main\webapp\resources\
目录中)

因此,我有一个
header.ftl
文件,它代表我所有页面的页眉:

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js is-ie8"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>MY WEBSITE</title>
        <meta name="robots" content="noindex,nofollow">

        <link rel="stylesheet" href="resources/css/webfont.css">
        <link rel="stylesheet" href="resources/bootstrap/css/bootstrap.min.css">
        <link rel="stylesheet" href="resources/bootstrap/css/bootstrap-theme.min.css">
        <link rel="stylesheet" href="resources/plugins/bs-select/bootstrap-select.min.css">
        <link rel="stylesheet" href="resources/plugins/bs-dialog/bootstrap-dialog.min.css">
        <link rel="stylesheet" href="resources/css/style.css" />

</head>

<body id="main">
    <div class="container page-header">
        <h1>My WebSite</h1>
    </div>
此项目中唯一的Spring xml配置文件名为web context.xml(它是配置FreeMarker的地方,并且是指定用于我的控制器的组件扫描的地方),此文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:sec="http://www.springframework.org/schema/security"

    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
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop.xsd">

    <context:annotation-config />

    <!-- Attivazione dei Proxy tramite aspetto -->
    <aop:aspectj-autoproxy />

    <context:property-placeholder location="classpath*:*.properties"
        ignore-resource-not-found="true" />

    <!-- Controller -->
    <context:component-scan base-package="it.istruzione.iam.ssum.registrazione">
    </context:component-scan>

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <mvc:resources mapping="/resources/**" location="/resources/" />

    <!-- Configurazione del resolver FreeMarker -->
    <!-- freemarker config -->
    <bean id="freemarkerConfig"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath" value="/WEB-INF/freemarker/" />
    </bean>

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="cache" value="true" />
        <property name="prefix" value="" />
        <property name="suffix" value=".ftl" />
    </bean>

    <!-- Configurazione MVC -->
    <mvc:annotation-driven />

</beans>
但它仍然不起作用,我无法访问放置在
/resources/
子目录中的CSS资源

当我在浏览器中显示上一页时,我在Eclipse控制台中获得与这些资源相关的以下错误消息:

16:55:40,249 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14) started (with errors) in 13261ms - Started 176 of 240 services (3 services failed or missing dependencies, 59 services are passive or on-demand)
16:55:42,623 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost/127.0.0.1:8080-1) No mapping found for HTTP request with URI [/iam-ssum-registrazione-web/] in DispatcherServlet with name 'dispatcher'
16:57:14,624 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost/127.0.0.1:8080-1) No mapping found for HTTP request with URI [/iam-ssum-registrazione-web/iscrizione/resources/css/webfont.css] in DispatcherServlet with name 'dispatcher'
16:57:14,640 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost/127.0.0.1:8080-1) No mapping found for HTTP request with URI [/iam-ssum-registrazione-web/iscrizione/resources/css/style.css] in DispatcherServlet with name 'dispatcher'
16:57:14,658 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost/127.0.0.1:8080-6) No mapping found for HTTP request with URI [/iam-ssum-registrazione-web/iscrizione/assets/js/modernizr-custom.js] in DispatcherServlet with name 'dispatcher'
16:57:14,659 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost/127.0.0.1:8080-3) No mapping found for HTTP request with URI [/iam-ssum-registrazione-web/iscrizione/resources/bootstrap/css/bootstrap-theme.min.css] in DispatcherServlet with name 'dispatcher'
16:57:14,661 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost/127.0.0.1:8080-4) No mapping found for HTTP request with URI [/iam-ssum-registrazione-web/iscrizione/resources/plugins/bs-select/bootstrap-select.min.css] in DispatcherServlet with name 'dispatcher'
16:57:14,664 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost/127.0.0.1:8080-5) No mapping found for HTTP request with URI [/iam-ssum-registrazione-web/iscrizione/resources/plugins/bs-dialog/bootstrap-dialog.min.css] in DispatcherServlet with name 'dispatcher'
16:57:14,664 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost/127.0.0.1:8080-2) No mapping found for HTTP request with URI [/iam-ssum-registrazione-web/iscrizione/resources/bootstrap/css/bootstrap.min.css] in DispatcherServlet with name 'dispatcher'

为什么??怎么了?我错过了什么?如何解决此问题?

您可以使用
JSTL
`确保URL正确:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<link href="<c:url value="/resources/css/webfont.css" />" rel="stylesheet">

编辑抱歉,我没有注意到这是一个免费标记页面:

<#import "/spring.ftl" as spring />

<link href="<@spring.url '/resources/css/webfont.css'/>" rel="stylesheet">


我真的可以在FreeMarker页面中使用JSTL吗?它与JSP页面无关吗?看起来我是wiredOk,但我认为将资源映射配置为SpringXML配置更清晰,但它不能work@AndreaNobili如果您直接呼叫
http://localhost:xxxx/yourProject/resources/css/webfont.css
你得到了什么?拉菲克·贝尔迪:打开这个URL:我获得CSS文件内容!!!问题是,正如您在我的原始帖子末尾所看到的,它尝试使用URL:/iam ssum registrizione web/iscrizione/resources/css/webfont.css来查找它(在项目名称之后,它尝试将resources文件夹查找到iscrizione文件夹中,该文件夹是打开页面的名称)事实上,它给了我以下错误消息:在DispatcherServlet中找不到URI为[/iam ssum registrazione web/iscrizione/resources/css/webfont.css]且名为“dispatcher”的HTTP请求的映射
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<link href="<c:url value="/resources/css/webfont.css" />" rel="stylesheet">
<#import "/spring.ftl" as spring />

<link href="<@spring.url '/resources/css/webfont.css'/>" rel="stylesheet">