`
izuoyan
  • 浏览: 8879426 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

使用sitemesh建立复合视图 - 3.其他讨论

阅读更多

使用sitemesh建立复合视图 - 1.hello

使用sitemesh建立复合视图 - 2.装饰器

使用sitemesh建立复合视图 - 3.其它讨论 <- now

前面的文章已经足以应用sitemesh来改善您的应用,但我发现还有一些其他的东东可能也会对大家有所帮助

可打印的界面装饰
前面说过有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开关来切换不同的装饰器页面。

 

中文问题
由于sitemesh内部所使用的缺省字符集为iso-8859-1,直接使用会产生乱码,我们可以通过以下方法纠正之:
  • 方法1:可以在您所用的application server的配置文件中找一找,有没有设置encoding或charset的项目,然后设成gbk或gb2312即可
  • 方法2:这也是我们一直使用的方法。
    1.在每一个jsp页里设置: <%@ page contentType="text/html; charset=gbk"%> 来告诉server你所要求的字符集。
    2.在每个jsp页的head中定义:<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=gbk"> 来告诉浏览器你所用的字符集。
总结:使用sitemesh最通常的途径:

1.配置好环境,

2.在WEB-INFO/decroators.xml中描述你将建立的包装器。

3.开发在decroators.xml中描述的包装器,最好存放在/_decorators目录下

4.ok ,可以看看辛勤的成果了 :)


资源:

关于作者:

陈鹏,西安东软公司。作为一名狂热的程序员希望每一天都能成长进步,并希望与大家分享快乐和知识。
请用以下方式和他联系:email chen56@msn.com

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics