111111
精灵王
精灵王
  • 注册日期2010-12-08
  • 发帖数640
  • QQ
  • 火币1103枚
  • 粉丝120
  • 关注75
  • 社区明星
阅读:3165回复:0

使用sitemesh建立复合视图 - 3.其他讨论-JSP教程,J2EE/EJB/服务器

楼主#
更多 发布于:2011-01-08 19:58
前面的文章已足以应用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 ,能看看辛勤的成果了 :)

更多黑客技术 黑客软件 计算机技术 编程技术 网站技术 qq技术 IT新闻 黑客基地 请访问 灯火安全联盟  灯火黑客 www.hack8888.com/bbs

喜欢0 评分0
游客

返回顶部