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