您的位置:首页 > 其它

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>
<sitemesh:write property='xxxx'/>标签就是原网页的内容(粗粒度的),可以多次加载


5.然后运行,打开要被渲染的网页 就行了。 原理:被渲染的网页 在输出前会因为上面的配置,其实会加载decorator.html网页,并输出。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: