• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

Sitemesh学习[0]

发布: 2007-7-01 18:47 | 作者: admin | 来源: | 查看: 12次 | 进入软件测试论坛讨论

领测软件测试网
使用sitemesh建立复合视图 - 1.hello
(作者:chen-neu ,提供给 huihoo.com 发布)
使用sitemesh建立复合视图 - 1.hello  <- now

使用sitemesh建立复合视图 - 2.装饰器  

使用sitemesh建立复合视图 - 3.其它讨论 

sitemesh是opensymphony团队开发的j2ee应用框架之一,旨在提高页面的可维护性和复用性。opensymphony的另一个广为人知的框架为webwork是用作web层的表示框架。他们都是开源的,可以在www.sf.net下找到。

应用于以下大项目的例子:http://opensource.thoughtworks.com/projects/sitemesh.html
www.jboss.org www.theserverside.com www.opensymphony.com www.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的定义:
<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>
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 defaultdir="/_decorators"> <decorator name="main" page="main.jsp"> <pattern>*</pattern> </decorator></decorators>


建立装饰器页面 /_decorators/main.jsp
<%@ 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>[email protected] </body></html>


建立一个的被装饰页面 /index.jsp(内容页面)
<%@ page contentType="text/html; charset=GBK"%><html> <head> <title>Agent Test</title> </head> <body> <p>本页只有一句,就是本句.</p> </body></html>

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



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

 

 

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网