前面说过有1种可打印的装饰器,可以允许你当用http://localhost/aaa/a.html?printable=true方式访问时,应用其他的装饰器(自己指定),给出原始页面以供打印(免得把header,footer等的花哨的图片也搭上)。 让我们来看一看怎样实现他: 1.首先在WEB-INFO/sitemesh.xml中设置: <mapper class="com.opensymphony.module.sitemesh.mapper.PrintableDecoratorMapper"> <param name="decorator" value="printable" /> <param name="parameter.name" value="printable" /> <param name="parameter.value" value="true" /> </mapper> 这样就可以通过?printable=true来使用名为printable的装饰器,而不是用原来的装饰器。 2.在WEB-INFO/decorators.xml中定义相应的printable装饰器 <decorator name="printable" page="printable.jsp"/> 3.最后编写printable装饰器/decorators/printable.jsp <%@ taglib uri="sitemesh-decorator" prefix="decorator" %> <html> <head> <title><decorator:title /></title> <decorator:head /> </head> <body>
<h1><decorator:title /></h1> <p align="right"><i>(printable version)</i></p>
<decorator:body />
</body> </html> |
这样就可以让一个原始页面通过?printable=true开关来切换不同的装饰器页面。 |