1 / 25

Sitemesh

分享人:王鸿雁. 页面组合利器. Sitemesh. 问题:如何加上头与脚 ?. 一个网站往往会有成百上千的页面,但为了给用户 比较好的感觉或是方便使用,这些页面上一般都会 相同的台头部门和脚注部分? 问:那么请问我们可以如何实现呢?. <body> <h1>this is header part</h1> < iframe src =“subPage.jsp”></ iframe > <h1>this is foot part</h1> </body>. 方法一: Iframe. 用户 不能直接访问 subPage.jsp

makaio
Download Presentation

Sitemesh

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 分享人:王鸿雁 页面组合利器 Sitemesh

  2. 问题:如何加上头与脚? 一个网站往往会有成百上千的页面,但为了给用户 比较好的感觉或是方便使用,这些页面上一般都会 相同的台头部门和脚注部分? 问:那么请问我们可以如何实现呢?

  3. <body> <h1>this is header part</h1> <iframesrc=“subPage.jsp”></iframe> <h1>this is foot part</h1> </body> 方法一:Iframe

  4. 用户不能直接访问subPage.jsp 如果你的网站(商城)采用iframe那么会出现 如下情况,你浏览后发现了一个有意思的商品, 但是没有办法把你看到的内容发给你的朋友(因为地址栏上显示的是不是子页面的地址),这将是多么懊恼的体验! 方法一:Iframe的缺点

  5. <jsp:include page=“head.jsp” /> Content…. <jsp:include page=“foot.jsp” /> 方法二:include

  6. 子页面需要手动的引入 head和foot页面?难维护! 方法二:include 缺点 难道没有更好的办法吗?

  7. SiteMesh 能帮助我们解决问题! Yes 就是它了!

  8. SiteMash是OpenSymphony开发的一款优秀的页面装饰器框架,在这之前apache 也开发了一款同类型的名叫tiles的同类型框架,相对于tiles来说 SiteMash更好用,被更广范的应用。 目前版本是 2.4.2版本. 1、sitemash介绍!

  9. 运行SiteMash有什么环境要求呢? 1、必须是j2ee web项目 2、必须是Servlet2.3或以上版本 2、SiteMash运行环境

  10. 3、SiteMash原理

  11. 往一个j2ee项目中添加siteMash的步骤: Step1:Add the SiteMesh library file to WEB-INF/lib 下载地址:http://wiki.sitemesh.org/download/attachments/294938/sitemesh-2.4.2.jar?version=1&modificationDate=1303412986333 4、5分钟添加Sitemash功能

  12. Step2:Add the SiteMesh filter to web.xml <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

  13. Step3: 创建一个空的decorators.xml 放在WEB-INF下面 <?xml version="1.0" encoding="UTF-8"?> <decorators defaultdir="/decorators"> </decorators>

  14. 到此 添加成功! 只不过目前SiteMash还没有帮我们做任何事情!

  15. 第一步:在/decorators目录下创建一个html文件(也可以是JSP)例:取名 myStyle.html。 添加装饰文件! <?xml version="1.0" encoding="UTF-8" ?> <%@ tagliburi="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <html > <head> <title></title> </head> <body > 这是一个装饰器文件 </body> </html>

  16. 第二步:将它配置成装饰器,并且告诉siteMash什么样的路径将使用该装饰器!第二步:将它配置成装饰器,并且告诉siteMash什么样的路径将使用该装饰器! <?xml version="1.0" encoding="UTF-8"?> <decorators defaultdir="/decorators"> <decorator name="basic-theme" page=" myStyle.html "> <pattern>/*</pattern> </decorator> </decorators>

  17. 我们随便创建一个JSP,然后访问该JSP试试? <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <head> <title>My JSP 'index.jsp' starting page 009</title> </head> <body> 这是目标页面 </body> </html>

  18. 没错! 我看到是的装饰器的内容,而我想要访问的页面的内容不见了 为什么呢?

  19. 我们看到的都是装饰器里的内容了。那怎以办呢?我们看到的都是装饰器里的内容了。那怎以办呢? 答:在装饰器里面引用 目标页面的内容。

  20. <decorator:body/> 引用目标文件 body里面的内容 <%@ tagliburi="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> <html > <head> <title></title> </head> <body> 这是一个装饰器文件 <hr/> <decorator:body /> </body> </html>

  21. <decorator:body />

  22. 引用目标页面标题 <decorator:title></decorator:title> 引用目标文件头部分 <decorator:head></decorator:head>

  23. 思考,我们能不能做出如下装饰器? 头部分 左 侧 菜 单 可以吗? 页尾部分

  24. SiteMash您会了吗?

  25. 谢谢!

More Related