一、環境搭建:html
(1)sitemesh.jar包加入 libweb
(2)decorators.xml 、sitemesh-decorator.tld、sitemesh-page.tld 拷貝到WEB-INFapp
(3)web.xml加配置以下:jsp
<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>url
(4)模板配置:spa
webRoot下建立文件夾myDecoratorsxml
示例模板:main.jsphtm
<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/WEB-INF/sitemesh-decorator.tld" prefix="decorator"%>
<html>
<head>
<title><decorator:title default="裝飾器頁面..." /></title>
<decorator:head />
</head>
<body >
sitemesh的例子
<hr>
<decorator:body />
<hr>
copyright xxx公司
</body>
</html>it
(5)decorators.xml配置以下io
<?xml version="1.0" encoding="ISO-8859-1"?>
<decorators defaultdir="/myDecorators"> <excludes> //過濾 <pattern>/sfeindex2/*</pattern>//這裏過濾是過濾訪問路徑 直接過濾/wel無效 </excludes> <decorator name="main" page="main.jsp"> <pattern>/sfeindex/wel</pattern> <pattern>/sfeindex2/wel</pattern> </decorator> <decorator name="main2" page="main2.jsp"> <pattern>/sfeindex/wel2</pattern> <pattern>/sfeindex2/wel2</pattern> </decorator> </decorators>