sitemesh是J2EE应用框架之一,用下面简单几个步骤就可以实现最简单的功能。
sitemesh的下载地址:opensymphony.sourceforge.net
1、copy sitemesh-2.3.jar 到 /WebRoot/WEB-INF/lib
2、copy sitemesh-decorator.tld、sitemesh-page.tld 到 /WebRoot/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>
<jsp-config>
<taglib>
<taglib-uri>sitemesh-page</taglib-uri>
<taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>sitemesh-decorator</taglib-uri>
<taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>
</taglib>
</jsp-config>
4、在/WebRoot/WEB-INF/下添加decorators.xml
<?xml version="1.0" encoding="UTF-8" ?>
<decorators defaultdir="/decorators">
<decorator name="frame" page="frame.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
5、在/WebRoot/下建目录decorators,并在decorators目录中建frame.jsp
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
<html>
<head>
<title>Demo - <decorator:title default="Welcome!" />
</title>
<decorator:head />
</head>
<body>
<div align="center">
<hr>
This is sitemesh Test!
<hr>
<decorator:body />
<hr>
2008 copyright jllb@163.com
</div>
</body>
</html>