r="/decorators">
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
创建WEB-INF/sitemesh.xml,这个文件是SiteMesh的配置文件,在这里定义了decorators.xml文件的 位置,同时还需要在这里定义希望使用的mapper。在SiteMesh中有许多mapper可以使用,可以参考 SiteMesh的文档。在这里我们使用ConfigDecoratorMapper。sitemesh.xml文件包含如下内容:
程序清单 4. sitemesh.xml <sitemesh>
<property name="decorators-file" value="/WEB- INF/decorators.xml" />
<excludes file="${decorators-file}" />
<page-parsers>
<parser content-type="text/html"
class="com.opensymphony.module.sitemesh.parser.FastPageParser" />
</page- parsers>
<decorator-mappers>
<mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
<param name="config" value="${decorators-file}" />
</mapper>
</decorator-mappers>
</sitemesh>
将下面的filter定义和映射加入到WEB-INF/web.xml文件中。这个filter的定义使特定的URL请求转到 SiteMesh进行处理。
程序清单 5. sitemesh filter设置 <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>
创建decorators/main.jsp,这个是在decorators.xml文件中配置的SiteMesh的模版文件。main.jsp文 件包含如下内容:
程序清单 6. main.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
prefix="decorator"% >
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<decorator:head />
<link rel="stylesheet" type="text/css" media="all"
href="/PHPonWASCE/styles/andreas01/theme.css" />
<title><decorator:title default="PHP on WAS CE" /></title>
</head>
<body>
<div id="page">
<div id="header" class="clearfix">PHP on WASCE</div>
<div id="content" class="clearfix">
<div id="main"><decorator:body /></div>
<div id="nav">
<div class="wrapper">
<h2 class="accessibility">Navigation</h2>
<div class="separator"></div>
<ul class="glassLis |