mayong--使用sitemesh建立复合视图 - 1.hello

来源:百度文库 编辑:神马文学网 时间:2024/04/24 16:56:18
[J2EE]使用sitemesh建立复合视图 - 1.hello
a.t.jamy 发表于 2005-7-22 下午 03:34:00
使用sitemesh建立复合视图 - 1.hello
sitemesh是opensymphony团队开发的j2ee应用框架之一,旨在提高页面的可维护性和复用性。opensymphony的另一个广为人知的框架为webwork是用作web层的表示框架。他们都是开源的,可以在www.sf.net下找到。
应用于以下大项目的例子:http://opensource.thoughtworks.com/projects/sitemesh.html
www.jboss.orgwww.theserverside.comwww.opensymphony.comwww.atlassian.com
sitemesh应用Decorator模式,用filter截取request和response,把页面组件head,content,banner结合为一个完整的视图。
通常我们都是用include标签在每个jsp页面中来不断的包含各种header, stylesheet, scripts and footer,现在,
在sitemesh的帮助下,我们可以开心的删掉他们了。如下图,你想轻松的达到复合视图模式,那末看完本文吧。

hello sitemesh:
在WEB-INF/web.xml中copy以下filter的定义: sitemesh
com.opensymphony.module.sitemesh.filter.PageFilter


sitemesh
/*

sitemesh-decorator
/WEB-INF/sitemesh-decorator.tld

sitemesh-page
/WEB-INF/sitemesh-page.tld

copy所需jar和dtd文件至相应目录,访问opensymphony.sourceforge.net的cvs以获取sitemesh最新版本。 sitemesh.jarWEB-INF/lib
sitemesh-decorator.tldWEB-INF
sitemesh-page.tldWEB-INF
建立WEB-INF/decorators.xml描述各装饰器页面(可仿照sitemesh例子)。

*


建立装饰器页面 /_decorators/main.jsp
<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="sitemesh-decorator" prefix="decorator" %>

<decorator:title default="装饰器页面..." />


sitemesh的例子



chen56@msn.com

建立一个的被装饰页面 /index.jsp(内容页面) <%@ page contentType="text/html; charset=GBK"%>

Agent Test

本页只有一句,就是本句.




最后访问index.jsp,将生成如下页面:

而且,所有的页面也会如同index.jsp一样,被sitemesh的filter使用装饰模式修改成如上图般模样
_xyz