0

Spring MVC + Apache tile 2 プロジェクトの構成は次のとおりです。

タイル構成

<定義名="test1" extends="mymain">
    <put-attribute name="main">
        <definition template="/WEB-INF/views/tiles/template/generictemplate.jsp">
            <put-attribute name="headerstyle" value="./resources/css/header.css" type="string" />
            <put-attribute name="genericcontent" value="/WEB-INF/views/tiles/test.jsp" />                 
        </定義>
    </プット属性>
</定義>
<定義名="test2" extends="mymain">
    <put-attribute name="main">
        <definition template="/WEB-INF/views/tiles/template/generictemplate.jsp">
            <put-attribute name="headerstyle" value="./resources/css/header.css" type="string" />
            <put-attribute name="genericcontent" value="/WEB-INF/views/tiles/test.jsp" />                 
        </定義>
    </プット属性>
</定義>

コントローラー

@RequestMapping(value="/test1", method=RequestMethod.GET)
    public String test1(@RequestParam(value="id", required=true) String id){
        「test1」を返します。
    }
@RequestMapping(value="/test2", method=RequestMethod.GET)
    パブリック文字列 test2(){
        「test2」を返します。
}

ビューの generictemplate.jsp

<%@ include file="include.jsp" %>
<tiles:importAttribute name="headerstyle" />
<link href="${headerstyle}" rel="stylesheet" type="text/css" />

<div role="main" class="main clearfix">
        <section class="generic">
            <div class="post">
                <tiles:insertAttribute name="genericcontent"/>
            </div>
        </セクション>
    <!-- メイン終了 -->
</div>

私の問題は 、test2 (パラメーターなし) を呼び出すときに、header.css を読み取ることができることです。しかし、test1 が呼び出されると、header.css に対して404 Not Foundが表示されます。ビューが次のパスで css にアクセスしようとしていることに気付きました

http://localhost:8080/myproject/test1/resources/css/header.css
それ以外の
http://localhost:8080/myproject/resources/css/header.css
test1 が呼び出しているとき。では、なぜ @RequestParam がこの違いを生むのでしょうか?

感謝。

4

1 に答える 1

0

これは、css が現在の URL に対して相対的に読み込まれているためです。test1 には、test1 の後にスラッシュを追加するパラメーターがあります。test2にはparamがないため、親ディレクトリに相対的です。

CSS の絶対パスを使用してみてください。

于 2012-11-20T18:17:37.863 に答える