源文件为:
http://wenku.baidu.com/view/433b1585d4d8d15abe234e3a.html下面我简单写下这个例子:
第一,首先配置环境:
(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文件
内容如下:
<decorators defaultdir="/decorators">
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
第三步:
根据decorators.xml文件里面的属性defaultdir在webroot下创建一个目录decorators,在该目录下创建一个main.jsp文件
内容如下:
<%@ 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="装饰器页面..." /></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目录下的一个共同使用的内容
<jsp:include page="/includes/footer.jsp"/>为includes目录下的一个共同使用的内容
<decorator:head /> 为每个要访问文件的内容
如下所示访问index.jsp
index.jsp内容为:
<%@ page contentType="text/html; charset=GBK"%>
<%@ include file="/includes/taglibs.jsp"%>
<html>
<head>
<title>Agent Test</title>
</head>
<body>
<p>本页只有就是本句.</p>
</body>
</html>
/includes/header.jsp内容为:
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!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=gbk">
</head>
<body>
sitemesh的例<hr>
</body>
</html>
/includes/footer.jsp内容为:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="gbk"%>
<!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=gbk">
<title>Insert title here</title>
</head>
<body>
<hr>chen56@msn.com
</body>
</html>
访问得到内容如下:
sitemesh的例
当然这里最主要的是要记住引入/include/taglibs.jsp
内容如下:
<%@ taglib uri="
http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
posted on 2013-05-15 16:04
Terry Zou 阅读(384)
评论(0) 编辑 收藏 所属分类:
Tomcat+Eclipse