2016-11-13 6 views
0

私のJSPページ用のresourcesフォルダに格納されている外部CSSファイルを使用する方法を解明しようとしています。私はこれまで、研究に基づいていくつかの異なることを試してきましたが、解決策はまだ見つかりませんでした。Spring Web MVCアプリケーションでJSPを使用するCSSを使用する

JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<!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=ISO-8859-1"> 
<title>ProjectX</title> 
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/homepage.css" /> 
</head> 
<body> 
    <h1>The message of the day is:</h1> 
    <p>${titleHomepage}</p> 
</body> 
</html> 

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

    <mvc:annotation-driven/> 

    <context:component-scan base-package="com.controllers"></context:component-scan> 

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

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/pages/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 

Folder Structure

私はまた、SRC /男性/リソースの内側に私のリソースファイルを配置するために、その優れた構造を信じてそれも私と一緒に遊んだりしようとしましたが、同じ結果を得ました上記の問題として。 FOUND

SOLUTION:

Full Folder Structure

答えて

0

問題は、私のmavenプロジェクトが、src/main/webappではなくWebContentフォルダから必要なファイルを取得しているということでした。

0

あなたが絞るの場所で、あなたのリソースフォルダを持ちます。

webapp/WEB-INF/resourcesまたは 変更パスservletConfig.xmlに直接添付されているwebappフォルダに入れます。 WEB-INF

+0

私はあなたの意見で混乱しています。私のリソースフォルダをwebappフォルダに入れて、webapp/resourcesに入れないと言っていますか? WEB-INFではなくwebapp内に常駐するようにリソースフォルダを再配置しましたが、CSSファイルにはまだアクセスできません。 – Brenton

+0

入力している間違いでした。申し訳ありません。サーバーを再デプロイして再起動しましたか?そしてあなたはブラウザのコンソールで何を得ているのですか? –

+0

src/main/webappにWEB-INFフォルダがあり、WebContentフォルダにWEB-INFフォルダがあります。私は異なっていると私は使用する必要がありますか分からない。 – Brenton

関連する問題