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.csstest1 が呼び出しているとき。では、なぜ @RequestParam がこの違いを生むのでしょうか?
感謝。