使用sitemesh建立复合视图 - 1.hello
sitemesh是opensymphony团队开发的j2ee应用框架之一,旨在提高页面的可维护性和复用性。opensymphony的另一个广为人知的框架为webwork是用作web层的表示框架。他们都是开源的,可以在www.sf.net下找到。
简介:
sitemesh应用Decorator模式,用filter截取request和response,把页面组件head,content,banner结合为一个完整的视图。通常我们都是用include标签在每个jsp页面中来不断的包含各种header, stylesheet, scripts and footer,现在,在sitemesh的帮助下,我们可以开心的删掉他们了。如下图,你想轻松的达到复合视图模式,那末看完本文吧。
hello sitemesh:
1.在WEB-INF/web.xml中copy以下filter的定义:
<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><taglib> <taglib-uri>sitemesh-decorator</taglib-uri> <taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location></taglib><taglib> <taglib-uri>sitemesh-page</taglib-uri> <taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location></taglib>
<decorators defaultdir="/_decorators"> <decorator name="main" page="main.jsp"> <pattern>*</pattern> </decorator></decorators>
<%@ page contentType="text/html; charset=GBK"%><%@ taglib uri="sitemesh-decorator" prefix="decorator" %><html> <head> <title><decorator:title default="装饰器页面..." /></title> <decorator:head /> </head> <body> sitemesh的例子<hr> <decorator:body /> <hr>chen56@msn.com </body></html>
<%@ page contentType="text/html; charset=GBK"%><html> <head> <title>Agent Test</title> </head> <body> <p>本页只有一句,就是本句.</p> </body></html>
