2017-06-23 14 views
0

私はTilesを初めて使用しています。 Spring MVCプロジェクトでJSPページをレイアウトしようとしています。Tilesでは、2つのJSPを1つのJSPに減らす方法はありますか?

私はファイルを持っている...私の具体的な質問が一番下にある...

を私がやっているを見て、これはそれを行うには「正しい」方法がある場合は私に知らせてくださいこのような構造...フォルダ/src/main/webapp/WEB-INF/layouts/は...

<tiles-definitions> 
    <definition name="standardLayout" template="/WEB-INF/layouts/standard.jsp"> 
     <put-attribute name="title" value="My Directory" /> 
     <put-attribute name="header" value="/WEB-INF/layouts/header.jsp" /> 
     <put-attribute name="body" value="" /> 
     <put-attribute name="footer" value="" /> 
    </definition> 
</tiles-definitions> 
tiles.xml

standard.jsp

// ... 
<html> 
    <title><tiles:insertAttribute name="title"/></title> 
// ... LOTS OF HTML ... 
    <tiles:insertAttribute name="header"/> 
    <tiles:insertAttribute name="body"/> 
    <tiles:insertAttribute name="footer"/> 
// ... LOTS OF HTML 
</html> 
// ... 

が含まれています

そして、私の閲覧可能なJSPはフォルダが含ま/src/main/webapp/WEB-INF/views/である...

家庭body.jsp

<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> 

<tiles:insertDefinition name="home"> 
    <tiles:putAttribute name = "body" value="/WEB-INF/views/home-body.jsp"/> 
</tiles:insertDefinition> 

home.jspを

<tiles-definitions> 
    <definition name="home" extends="standardLayout"> 
    </definition> 
</tiles-definitions> 

tiles.xml

<div> 
// LOTS OF HTML FOR THE BODY OF THE HOME PAGE 
</div> 

質問:ただ持っていたいですhome.jsp bそれは別のファイルから本文の内容(と他のコンテンツ)を引き出す必要があるように見えます。 home.jsphome-body.jspを1つのファイルに単純化する適切な方法はありますか、それとも実際にこれをすべて正しく実行していますか?

答えて

0
あなたのtiles.xml、standard.jspを更新し、以下のようにhome.jspをする必要が

<html> 
    <title><tiles:insertAttribute name="title"/></title> 
    <header> 
     <tiles:insertAttribute name="header"/> 
    </header> 
    <body> 
     <tiles:insertAttribute name="body"/> 
    </body> 
    <footer> 
     <tiles:insertAttribute name="footer"/> 
    </footer> 
</html> 
standard.jsp

<tiles-definitions> 
    <definition name="home" extends="standardLayout"> 
     <put-attribute name="body" value="/WEB-INF/views/home.jsp"></put-attribute> 
    </definition>   
</tiles-definitions> 

tiles.xml

home.jsp

<!-- Actual body content goes here.. -->  
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>  
<p>The content of the home page.</p> 
関連する問題