3.1.1、引入相关jar
3.1.2、配置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.2、定义装饰器(decorator)
3.2.1、创建页面(decorator.html)or jsp/freemaker
<html>
<head>
<title>SiteMesh example: <sitemesh:write property='title'/></title>
<sitemesh:write property='head'/>
</head>
<body>
<h1 class='title'>
SiteMesh example site: <sitemesh:write property='title'/>
</h1>
<div class='mainBody'>
<sitemesh:write property='body'/>
</div>
<div class='disclaimer'>Site disclaimer. This is an example.</div>
</body>
</html>
3.2.2、创建配置(sitemesh3.xml)
<sitemesh>
<mapping path="/*" decorator="/decorator.html"/>
</sitemesh>
3.3、定义内容页
<html>
<head>
<title>Hello World</title>
<meta name='description' content='A simple page'>
</head>
<body>
<p>Hello <strong>world</strong>!</p>
</body>
</html>
3.4、最终输出效果
<html>
<head>
<title>SiteMesh example: Hello World</title>
<meta name='description' content='A simple page'>
</head>
<body>
<h1 class='title'>SiteMesh example site: Hello World</h1>
<div class='mainBody'>
<p>Hello <strong>world</strong>!</p>
</div>
<div class='disclaimer'>Site disclaimer. This is an example.</div>
</body>
</html>
联系客服