1、Install sitemesh
access opensymphony.sourceforge.net to get sitemesh.jar、sitemesh-decorator.tld and sitemesh-page.tld
put
put
2、configure sitemesh
2.1、add following contents into 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>
2.2、add to label into web.xml
<taglib>
<taglib-uri>/WEB-INF/sitemesh-decorator.tld</taglib-uri>
<taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/sitemesh-page.tld</taglib-uri>
<taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
</taglib>
3、build up decorators.xml under /WEB-INF/
<decorators defaultdir="/decorators"><decorator name="frame" page="frame.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
its means that decorators bind frame.jsp and a decorator named frame.
when you right click decorators.xml file under netbeans IDE ,choose confirm xml,you will get following messages:
已启动 XML 验证。
正在检查 file:/E:/project/demonetbeansstructDBLog4jtestSitemesh/web/WEB-INF/decorators.xml...
cvc-elt.1: Cannot find the declaration of element 'decorators'. [12]
已完成 XML 验证。
take it easy ,reboot glassfish v3,the project will use decorator technology normoally.
4、build up frame.jsp under \web\decorators
<%@taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<!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=UTF-8">
<title>Demo-<decorator:title default="Welcome!" /></title>
<decorator:head />
</head>
<body>
<div align="center"><%if(session.getAttribute("username")!=null){%>
<table width="100%">
<tr>
<td><img src="images/1.png"</td>
<td><img src="images/2.png"</td>
</tr>
<tr>
<td colspan="2">
<hr>
</td>
</tr>
<tr>
<td><decorator:body /></td>
</tr>
</table>
<%} else {%><decorator:body /><% } %>
<hr>
2009copyright wei.guan@sun.com </div>
</body>
</html>