2016-12-10 3 views
0

Ich habe ein Problem beim Verbinden der CSS- und JS-Datei aus dem Ressourcenverzeichnis gefunden.Netbeans Spring kann keine Ressourcendatei finden

Verzeichnisstruktur:

enter image description here

JSP Datei:

<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %> 

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
    <spring:url value="/resources/css/style.css" var="mainCss" /> 

    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <title>Project Name</title>   
    <link href="${mainCss}" rel="stylesheet" /> 

    </head> 
    <body> 
    </body> 
</html> 

applicationContext.xml Datei:

<?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:aop="http://www.springframework.org/schema/aop" 
      xmlns:tx="http://www.springframework.org/schema/tx" 
      xmlns:mvc="http://www.springframework.org/schema/mvc" 
      xmlns:context="http://www.springframework.org/schema/context" 
      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-4.0.xsd 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> 


    <context:annotation-config /> 
    <context:component-scan base-package="com.controller"/> 
    <mvc:default-servlet-handler/> 
    <mvc:annotation-driven/>  

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
     <property name="basename" value="messages" /> 
    </bean> 
</beans> 

Wenn ich überprüfen, was unter Stylesheet-Datei in der Konsole ist, ich gefunden:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8080/ProjectName/resources/css/style.css".

Pfad auf Anwendungsindex umgeleitet wird.

Haben Sie eine Idee, wie Sie es beheben können? Was hat das Problem verursacht?

+0

/Ressourcen sollten nicht im Weg sein, zu ändern, wenn Sie die Seite Markup schreiben. Sie müssen Ihre App in einem WAR packen und CSS und JavaScript im Kontextstammverzeichnis ablegen. – duffymo

Antwort

0

Können Sie versuchen

<spring:url value="/resources/css/style.css" var="mainCss" /> 

mit

<spring:url value="./resources/css/style.css" var="mainCss" />