源文件為:
http://wenku.baidu.com/view/433b1585d4d8d15abe234e3a.html下面我簡(jiǎn)單寫(xiě)下這個(gè)例子:
第一,首先配置環(huán)境:
(1)添加jar包,如:sitemesh-2.4.1.jar放在lib下
在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>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
第二步:
在WEB-INF下新建decorators.xml文件
內(nèi)容如下:
<decorators defaultdir="/decorators">
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
第三步:
根據(jù)decorators.xml文件里面的屬性defaultdir在webroot下創(chuàng)建一個(gè)目錄decorators,在該目錄下創(chuàng)建一個(gè)main.jsp文件
內(nèi)容如下:
<%@ page contentType="text/html; charset=GBK"%>
<%@ include file="/includes/taglibs.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title><decorator:title default="裝飾器頁(yè)面..." /></title>
<decorator:head />
</head>
<body>
<div id="page">
<div id="header">
<jsp:include page="/includes/header.jsp"/>
</div>
<div id="content">
<decorator:body />
</div>
<div id="footer">
<jsp:include page="/includes/footer.jsp"/>
</div>
</body>
</html>
第四步
<jsp:include page="/includes/header.jsp"/>為includes目錄下的一個(gè)共同使用的內(nèi)容
<jsp:include page="/includes/footer.jsp"/>為includes目錄下的一個(gè)共同使用的內(nèi)容
<decorator:head /> 為每個(gè)要訪(fǎng)問(wèn)文件的內(nèi)容
如下所示訪(fǎng)問(wèn)index.jsp
index.jsp內(nèi)容為:
<%@ page contentType="text/html; charset=GBK"%>
<%@ include file="/includes/taglibs.jsp"%>
<html>
<head>
<title>Agent Test</title>
</head>
<body>
<p>本頁(yè)只有就是本句.</p>
</body>
</html>
/includes/header.jsp內(nèi)容為:
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
</head>
<body>
sitemesh的例<hr>
</body>
</html>
/includes/footer.jsp內(nèi)容為:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<hr>chen56@msn.com
</body>
</html>
訪(fǎng)問(wèn)得到內(nèi)容如下:
sitemesh的例
當(dāng)然這里最主要的是要記住引入/include/taglibs.jsp
內(nèi)容如下:
<%@ taglib uri="
posted on 2013-05-15 16:04
Terry Zou 閱讀(390)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
Tomcat+Eclipse