Struts 内置了Tiles,利用它可以很好复用页面,使用起来就像我们复用类一样。
Sitemesh使用Decorator模式达到预期效果。这里可以将页面分为两类,decorator(修饰)和decoratored(被修饰)。这就好比有一个相框和各种不同可以用来变换的相片,当相框中放入不同的相片,就得到不同的视觉效果。
<card title='<tiles:getAsString name="title"/>'>
<tiles:insertAttribute name="menu" />
<tiles:insertAttribute name="body" />
<tiles:insertAttribute name="footer" />
</card>
<definition name="basic" template="/decorators/main.jsp">
<put-attribute name="title" value="example" />
<put-attribute name="menu" value="/decorators/menu.jsp" />
<put-attribute name="body" value="/decorators/blank.jsp" />
<put-attribute name="footer" value="/decorators/footer.jsp" />
</definition>
Sitemesh使用Decorator模式达到预期效果。这里可以将页面分为两类,decorator(修饰)和decoratored(被修饰)。这就好比有一个相框和各种不同可以用来变换的相片,当相框中放入不同的相片,就得到不同的视觉效果。
<html>
<head>
<title>My Site - <decorator:title default="Welcome!" /></title>
<decorator:head />
</head>
<body>
<page:applyDecorator name="panel"/>
<decorator:body />
<p><small>(<a href="?printable=true">printable version</a>)</small></p>
<page:applyDecorator name="footer"/>
</body>
</html>
<decorators defaultdir="/decorators">
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>
<decorator name="panel" page="panel.jsp"/>
<decorator name="footer" page="footer.jsp"/>
</decorators>