| 首页 | 新闻 | 网页 | 设计 | 色彩 | 原创 | 视觉 | 素材 | 动漫 | 酷站 | 策划 | 文案 | 访谈 | 运营 | 编程 | 数据库 | 服务器 | 下载 | 图库 | 
您的位置: 幽幽天空 > 网页 > 编程开发 > Java教程 > J2EEEJBJMS > 文章正文 用户登录
google使用技巧
我的餐馆点评网站
像素字体使用技巧
ViewletBuilder 4
使用report build
使用 Flash Remot
未公开的Flash MX
关于color对象的使
谈谈自己使用flas
在Flash MX中使用

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

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

作者:佚名 来源:http://www.j2eesp.com 更新:2006-8-25 21:05:35 错误报告 我要投稿

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:
  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>

  2. copy所需jar和dtd文件至相应目录,访问opensymphony.sourceforge.net的cvs以获取sitemesh最新版本。
    sitemesh.jar WEB-INF/lib
    sitemesh-decorator.tld WEB-INF
    sitemesh-page.tld WEB-INF

  3. 建立WEB-INF/decorators.xml描述各装饰器页面(可仿照sitemesh例子)。
    <decorators defaultdir="/_decorators">     
    <decorator name="main" page="main.jsp">
    <pattern>*</pattern> </decorator>
    </decorators>



  4. 建立装饰器页面 /_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>chen56@msn.com </body>
    </html>


  5. 建立一个的被装饰页面 /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标签。

文章录入:skyuu    责任编辑:skyuu 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    发表评论:
    姓名:  评 分: 1分 2分 3分 4分 5分
     
  • 严禁发表危害国家安全、政治、黄色淫秽等内容的评论。
  • 用户需对自己在使用幽幽天空服务过程中的行为承担法律责任。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表机友个人观点,与本网站立场无关。