<?xml version="1.0" encoding="GBK"?> <!-- defaultdir指定装饰器文件所在的路径 --> <decorators defaultdir="/decorators"> <!-- 指定main装饰器,该装饰器使用main.jsp页面 --> <decorator name="main" page="main.jsp"> <!-- 使用main装饰器装饰所有的JSP页面 --> <pattern>*</pattern> </decorator> </decorators>3,定义原始页面,也就是被装饰的页面
main.jsp-- <%@ page contentType="text/html; charset=GBK"%> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%> <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%> <html> <head> <title><decorator:title default="SiteMesh的装饰器页"/></title> <link href="decorators/main.css" rel="stylesheet" type="text/css"> <decorator:head/> </head> <body> <table width="100%" height="100%"> <tr> <td valign="top"> <!-- 引入一个页面,临时指定所用的装饰器 --> <page:applyDecorator page="/book.html" name="panel" /> <page:applyDecorator page="/link.html" name="panel" /> </td> <td width="100%"> <table width="100%" height="100%"> <tr> <td id="pageTitle"> <decorator:title/> </td> </tr> <tr> <td valign="top" height="100%"> <decorator:body /> </td> </tr> <tr> <td id="footer"> <b>被包含的内容</b><br> SithMesh提供页面装饰支持 </td> </tr> </table> </td> </tr> </table> </body> </html>--------------
main.css-- body, td, p { font: normal x-small verdana, arial, helvetica, sans-serif; } .panelTitle { background-color: #003399; color:#eeeeee; font-weight: bold; border-color: #3366ff #000033 #000033 #3366ff; border-width: 1; border-style: solid; padding: 1; } .panelBody { background-color: #eeeeee; border-color: black; border-width: 0 1 1 1; border-style: solid; padding: 2; } #pageTitle { background-color: #003399; color:#eeeeee; font-weight: bold; font-size: large; border-color: #3366ff #000033 #000033 #3366ff; border-width: 1; border-style: solid; padding: 1; text-align: center; } #footer { background-color:#eeeeee; font-size: 9pt; text-align: center; color: black; border-color: #666666 #cccccc #cccccc #666666; border-width: 1; border-style: solid; padding: 1; }--------------
panel.jsp-- <%@ page contentType="text/html; charset=GBK"%> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <p> <table width=250 border=0 cellpadding=0 cellspacing=0> <tr> <th class="panelTitle"> <decorator:title default="小面板页面" /> </th> </tr> <tr> <td class="panelBody"> <decorator:body /> </td> </tr> </table> </p>-------------
<?xml version="1.0" encoding="GBK"?> <decorators defaultdir="/decorators"> <!-- 在excludes元素下指定的页面将不会由SiteMesh来装饰 --> <excludes> <pattern>/exclude.jsp</pattern> <pattern>/exclude/*</pattern> </excludes> <!-- 创建一个名为main的装饰器,该装饰器页面为main.jsp, 用于装饰pattern指定的URL的所有页面--> <decorator name="main" page="main.jsp"> <pattern>/*</pattern> </decorator> <!-- 定义一个装饰器,但该装饰器默认不装饰任何页面 --> <decorator name="panel" page="panel.jsp"/> </decorators>---------
<filter> <filter-name>struts-cleanup</filter-name> <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> </filter> <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class> </filter> <filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts-cleanup</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>============================================================================
<filter> <filter-name>struts-cleanup</filter-name> <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> </filter> <filter> <filter-name>sitemesh</filter-name> <filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class> </filter> <filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts-cleanup</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>--------------------
<?xml version="1.0" encoding="GBK"?> <decorators defaultdir="/decorators"> <!-- 在excludes元素下指定的页面将不会由SiteMesh来装饰 --> <excludes> <pattern>/exclude.jsp</pattern> <pattern>/exclude/*</pattern> </excludes> <!-- 创建一个名为main的装饰器,该装饰器页面为main.jsp, 用于装饰pattern指定的URL的所有页面--> <decorator name="main" page="main.ftl"> <pattern>/*</pattern> </decorator> </decorators>------------------
${title},${head},${body}. mail.ftl-- <#assign page=JspTaglibs["/WEB-INF/sitemesh-page.tld"]> <html> <head> <title>${title}></title> <link href="decorators/main.css" rel="stylesheet" type="text/css"> ${head} </head> <body> <table width="100%" height="100%"> <tr> <td valign="top"> <p> <table width=250 border=0 cellpadding=0 cellspacing=0> <tr> <th class="panelTitle"> 作者图书 </th> </tr> <tr> <td class="panelBody"> <center> Spring2.0宝典<br> 轻量级J2EE企业应用实战<br> 基于J2EE的Ajax宝典 </center> </td> </tr> </table> </p> <p> <table width=250 border=0 cellpadding=0 cellspacing=0> <tr> <th class="panelTitle"> 友情链接 </th> </tr> <tr> <td class="panelBody"> <center> <a href="http://www.nit-pro.org">NIT-PRO考试中心</a><br> <a href="http://www.oneedu.cn">新东方IT培训中心</a><br> <a href="http://www.oneedu.cn">东方标准人才服务公司</a><br> </center> </td> </tr> </table> </p> </td> <td width="100%"> <table width="100%" height="100%"> <tr> <td id="pageTitle"> ${title} </td> </tr> <tr> <td valign="top" height="100%"> ${body} </td> </tr> <tr> <td id="footer"> <b>被包含的内容</b><br> SithMesh提供页面装饰支持 </td> </tr> </table> </td> </tr> </table> </body> </html>-----------------------------------
别忘了要把sitemesh-decorator.tld和sitemesh-page.tld复制到Web-inf下。