sitemesh3 网页输出装饰器
2016-07-19 11:25
344 查看
1.从官网下载一个jar包 sitemesh-3.0.1.jar
2.在web项目里的web.xml 添加过滤器
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>3.新建sitemesh3.xml ,名字必须是sitemesh3
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<!-- 指明满足“/*”的页面,将被“/WEB-INF/views/decorators/decorator.html”所装饰 -->
<mapping path="/*" decorator="/decorator.html" />
<!-- 指明满足“/exclude.jsp*”的页面,将被排除,不被装饰 -->
<mapping path="/exclude.jsp*" exclue="true" />
</sitemesh>4.设置decorator.html
<!DOCTYPE html>
<html>
<head>
<title>SiteMesh example: <sitemesh:write property='title'/></title>
<style type='text/css'>
/* Some CSS */
body { font-family: arial, sans-serif; background-color: #ffffcc; }
h1, h2, h3, h4 { text-align: center; background-color: #ccffcc;
border-top: 1px solid #66ff66; }
.mainBody { padding: 10px; border: 1px solid #555555; }
.disclaimer { text-align: center; border-top: 1px solid #cccccc;
98c9
margin-top: 40px; color: #666666; font-size: smaller; }
</style>
<sitemesh:write property='head'/>
</head>
<body>
<h1 class='title'>this is a title<sitemesh:write property='title'/></h1>
<div class='mainBody'>
this BODY<sitemesh:write property='body'/>fff<sitemesh:write property='body'/>
</div>
<div class='disclaimer'>Site disclaimer. This is an example.</div>
</body>
</html>
5.然后运行,打开要被渲染的网页 就行了。 原理:被渲染的网页 在输出前会因为上面的配置,其实会加载decorator.html网页,并输出。
2.在web项目里的web.xml 添加过滤器
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>3.新建sitemesh3.xml ,名字必须是sitemesh3
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<!-- 指明满足“/*”的页面,将被“/WEB-INF/views/decorators/decorator.html”所装饰 -->
<mapping path="/*" decorator="/decorator.html" />
<!-- 指明满足“/exclude.jsp*”的页面,将被排除,不被装饰 -->
<mapping path="/exclude.jsp*" exclue="true" />
</sitemesh>4.设置decorator.html
<!DOCTYPE html>
<html>
<head>
<title>SiteMesh example: <sitemesh:write property='title'/></title>
<style type='text/css'>
/* Some CSS */
body { font-family: arial, sans-serif; background-color: #ffffcc; }
h1, h2, h3, h4 { text-align: center; background-color: #ccffcc;
border-top: 1px solid #66ff66; }
.mainBody { padding: 10px; border: 1px solid #555555; }
.disclaimer { text-align: center; border-top: 1px solid #cccccc;
98c9
margin-top: 40px; color: #666666; font-size: smaller; }
</style>
<sitemesh:write property='head'/>
</head>
<body>
<h1 class='title'>this is a title<sitemesh:write property='title'/></h1>
<div class='mainBody'>
this BODY<sitemesh:write property='body'/>fff<sitemesh:write property='body'/>
</div>
<div class='disclaimer'>Site disclaimer. This is an example.</div>
</body>
</html>
<sitemesh:write property='xxxx'/>标签就是原网页的内容(粗粒度的),可以多次加载
5.然后运行,打开要被渲染的网页 就行了。 原理:被渲染的网页 在输出前会因为上面的配置,其实会加载decorator.html网页,并输出。
相关文章推荐
- spring笔记——Ioc控制反转
- DBA learning---2
- 林子雨老师团队《Architecture of a Database System》 中文版
- Java集合中Comparator和Comparable接口的使用
- 油水井图片库开发总结
- mysql主键insert into
- 百度地图开发(三)之地图控制 + 定位
- unity3d之VS2013默认编辑器问题
- 一场.user.ini引发的血案
- DBA learning--1
- Comparable和Comparator(后面补充上)
- 并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法
- C++多态的实现机制深入理解
- poj1743Musical Theme - 后缀数组
- tomcat+tengine+redis+postgresql
- 安卓自定义View——网易颜色渐变效果指示器
- Solr4.3.1+Tomcat7.0.37配置
- shell一个实例$(($a+1))
- 由Unity5.3.3f1引发的一场血案
- 计算两个日期相隔多少年,多少月,多少天