1.包文件
Sitemesh.jar文件复制到WebRoot/WEB-INF/lib目录下
Sitemesh-decorator.tld,sitemesh-page.tld是标签库文件复制到WebRoot/WEB-INF
2.配置Sitemesh框架
(1)在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>
(2)配置Sitemesh标签库,在web.xml中添加两个Sitemesh的标签库
<jsp-config>
<taglib>
<taglib-uri>sitemesh-decorator</taglib-uri>
<taglib-location>/WEB-INF/sitemesh-decorator.tld
</taglib-location>
</taglib>
<taglib>
<taglib-uri>sitemesh-page</taglib-uri>
<taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
</taglib>
</jsp-config>
3.建立装饰器描述文件/WebRoot/WEB-INF/decorators.xml
<decorators defaultdir="/decorators">
<decorator name="frame" page="frame.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
4.建立装饰器页面/WebRoot/decorators/frame.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
prefix="decorator"%>
<html>
<head>
<title>Demo - <decorator:title default="Welcome!" /></title>
<link rel="stylesheet" type="text/css" href="styles.css">
<decorator:head />
</head>
<body>
<div align="center"><%if ((String)session.getAttribute("username") != null) {%>
<table width="100%">
<tr>
<td><img src='images/logo4.png'></td>
<td><img src='images/logo2.png' height="90"></td>
</tr>
<tr>
<td colspan="2">
<hr>
</td>
</tr>
<tr>
<td width="160" bgcolor="#EEEEEE" valign="top">
<table width="100%">
<tr>
<td><li><a href="welcome.do">Main</a></li></td>
</tr>
<tr>
<td><li><a href="address.do?method=list">Address</a></li></td>
</tr>
<tr>
<td><li><a href="menu1.do">Menu1</a></li></td>
</tr>
<tr>
<td><li><a href="menu2.do">Menu2</a></li></td>
</tr>
</table>
</td>
<td align="left" valign="top"><decorator:body /></td>
</tr>
</table>
<%} else {%> <decorator:body /> <%}%>
<hr>
版权信息:2008.10.18</div>
</body>
</html>