sitemesh入门
1、环境搭建:
(1)sitemesh.jar包加入 lib
(2)decorators.xml 、sitemesh-decorator.tld、sitemesh-page.tld 拷贝到WEB-INF
(3)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>
</filter-mapping>
(4)模板配置:
webRoot下创建文件夹myDecorators
示例模板:main.jsp
<%@ 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>
(5)decorators.xml配置如下
<?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>