1 环境:myeclipse,tomcat,jdk1.6
2. (1)新建web工程sitemeshDemo:
(2)下载sitemesh.jar, sitemesh-decorator.tld,sitemesh-page.tld 地址http://www.opensymphony.com
将sitemesh.jar复制到WEB-INF/lib,sitemesh-decorator.tld和sitemesh-page.tld 复制到WEB-INF下;
(3)修改web.xml,加入如下内容
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>
com.opensymphony.module.sitemesh.filter.PageFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.在WebRoot下建立文件夹myDecorators;在WEB-INF下建立 decorators.xml内容如下
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/myDecorators">
<decorator name="main" page="main.jsp">
<pattern>*</pattern>
</decorator>
</decorators>
4 在WebRoot/myDecorators下新建两个页面main.jsp,index.jsp
其中main.jsp内容如下
<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/WEB-INF/sitemesh-decorator.tld" prefix="decorator" %>
<html>
<head>
<title><decorator:title default="装饰器页面..." /></title>
<decorator:head />
</head>
<body>
sitemesh的例子<hr>
<decorator:body />
<hr>copyright xxx公司
</body>
</html>
被装饰的页面index.jsp内容如下
<%@ page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>Agent Test</title>
</head>
<body>
<p>你可以在这里加入你的内容.</p>
</body>
</html>
5.发布运行项目,在浏览器地址栏输入http://10.0.12.207:8080/SsitemeshDemo/myDecorators/index.jsp, 成功了!