可打印的装饰器,可以允许你当用http://localhost/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" %> |
这样就可以让一个原始页面通过?printable=true开关来切换不同的装饰器页面。
注:
printable:打印被装饰的页面:index.jsp和printable.jsp页面中的内容。不会打印main.jsp页面中的内容,使用提供的demo的printable的运行截图为: