继上一章http://www.cnblogs.com/EasonJim/p/7083165.html中使用的例子中,是通过decorators.xml文件通过URL匹配进行转换的。

而下面这种方法是通过sitemesh.xml的PageDecoratorMapper映射器来转换的,而无需匹配URL,只需在meta头指定decorator中的模板即可。

下面是操作步骤:

1、在sitemesh.xml中添加PageDecoratorMapper映射器,并指定meta的名称规则

        <mapper class="com.opensymphony.module.sitemesh.mapper.PageDecoratorMapper">
<param name="property.1" value="meta.decorator" />
<param name="property.2" value="decorator" />
<!-- 注意这一行指定<meta/>标签的 name 属性作为PageDecorator的识别符号 -->
<param name="property.3" value="meta.theme" />
</mapper>

用法:

①<meta name="decorator" content="basic-theme" />

②<meta name="them" content="basic-theme" />

③<param name="property.2" value="decorator" />这个用法在下方将有说明。

注意:content指定的就是在decorators.xml文件中docorator的模板名称。

2、在decorators.xml的模板配置还是使用原来的

<decorators defaultdir="/decorators">
<decorator name="basic-theme" page="basic-theme.jsp">
<pattern>/data/*</pattern>
</decorator>
</decorators>

3、在根目录新建index.jsp页面,内容如下:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="decorator" content="basic-theme" />
<title>应该是内容页面</title>
</head>
<body>
<h1>Weekdays</h1>
<p>5:00pm - 10:00pm</p>
<p>Weekends</p>
<p>5:00pm - 10:00pm</p>
</body>
</html>

4、测试效果如下:

5、<param name="property.2" value="decorator" />的用法

①新建test.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html decorator="basic-theme">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<h1>Test</h1>
</body>
</html>

②直接访问test.jsp页面,得到的效果就是使用了模板页面的,效果如下:

测试工程:https://github.com/easonjim/5_java_example/tree/master/sitemesh/test2

参考:

http://wiki.sitemesh.org/wiki/display/sitemesh/Decorating+Beyond+URL+Patterns

https://my.oschina.net/yangning/blog/110487

https://web.archive.org/web/20071008180624/http://www.opensymphony.com/sitemesh/api/com/opensymphony/module/sitemesh/mapper/PageDecoratorMapper.html

最新文章

  1. $event 获取对象
  2. java布局学习 (三)
  3. Mysql LIMIT如何正确对其进行优化
  4. windows下 mysql忘记密码怎么办
  5. Python实现SVM(支持向量机)
  6. 当WEB站点应用程序池标识为ApplicationPoolIdentity,出现运行错误时的解决方法
  7. Oracle数据库作业-6 查询“张旭“教师任课的学生成绩。
  8. Qt学习总结-ui篇
  9. WPF跨程序集共享样式(跨程序集隔离样式和代码)
  10. java_设计模式_迭代器模式_Iterator Pattern(2016-08-12)
  11. poj 2632 Crashing Robots_模拟
  12. localStorage请使用getItem 和setITem
  13. Caused by: java.lang.IllegalStateException: RedisConnectionFactory is required
  14. springMVC入门思路整理
  15. oo第二单元作业总结
  16. office2007每次打开都要配置文件,怎么取消配置
  17. JS 强制类型转化
  18. 2602 ACM 杭电 骨头容器 01背包
  19. 01.File文件基本操作
  20. Idea设置默认不折叠一行的函数

热门文章

  1. 【NOIP模拟赛】一道挖掉背景的数学题
  2. CSS + radius 五环
  3. 查询编辑器便捷特性【MSSQL】
  4. hanframe开微博了
  5. 【Android学习笔记】Mac下Android Studio开发环境搭建
  6. CherryPy 入门
  7. 三维重建:GitHub百度Apollo 2.0
  8. 【转载】原 IntelliJ IDEA (idea)引入eclipse web项目
  9. scala学习(1)----map和flatMap的区别
  10. STL源码分析之空间配置器