2016-09-26 20 views
0

静的ファイル(CSS、JSなど)をSpringを使用して提供するためのチュートリアルをいくつかご紹介しましたが、私の静的ファイルを見ることができるはずですが、 。Springで静的コンテンツを提供する

マイspring-web-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:context="http://www.springframework.org/schema/context" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <context:component-scan base-package="brass.ducks" /> 

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

    <mvc:resources mapping="/styles/**" location="views" /> 
    <mvc:annotation-driven/> 

</beans> 

最後の行はstyles/whatever.cssを次のいずれかのURLはフォルダ私の見解で見て、そこから役立つはずであることを示唆しています。たとえば、私のページにはスタイルシートへのリンクが/styles/css/bootstrap.min.css(これはhttp://localhost:8080/Brass-Ducks/styles/css/bootstrap.min.cssになります)がありますが、これは自分のスタイルシートには反映されません。

マイフォルダ階層は、次のようになります

enter image description here

私は何かが足りないのですか?

:私はこのように見えるために私 web.xmlを変更した

enter image description here

としては、私は私の.warファイルを抽出し、フォルダ階層は次のようになりた提案

EDIT

<mvc:resources mapping="/styles/**" location="/WEB-INF/views/" /> <mvc:annotation-driven/> 

しかし、URL http://localhost:8080/Brass-Ducks/styles/css/bootstrap.min.css st病気はCSSファイルを解決しません。

答えて

-1

はい、あなたは/が欠落している、それは次のようになります。あなたのstylesディレクトリに移動し

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

をし、XMLは本当に、春を設定するJavaの設定をしようとするのは良い考えではない..です

+0

'にhttp:// localhost:8080 /真鍮-アヒル/スタイル/ CSS/bootstrap.min.css'それでもスタイルシートは表示されません。 – Nanor

+0

@Nanorファイルブラウザで 'war'ファイルを開き、存在すればチェックアウトします。応答は '404'ですか? – Jaiwo99

+0

私のファイルブラウザで '.war'ファイルが見えますが、私はあなたが意味することに従いません。 – Nanor

1

/webapp/resoursesパス。だから/webapp/resourses/stylesになります。 <mvc:resources mapping="/styles/**" location="/resources/styles/"でXML設定を変更してまで、あなたのマッピングの設定を変更しhttp://localhost:8080/Brass-Ducks/styles/css/bootstrap.min.css

0

から取得しよう:

<mvc:resources mapping="/styles/**" location="/WEB-INF/views/styles/" /> 
関連する問題