Site Mesh是open symphony团队开发的j2ee应用框架之一,是一个用来在JSP中实现页面布局和装饰(layout and decoration)的框架组件,能够帮助网站开发人员较容易实现页面中动态内容和静态装饰外观的分离,旨在提高页面的可维护性和复用性。Site Mesh是开源的,可以在www.sf.net下找到。
Site mesh应用Decorator模式,用filter截取request和response,把页面组件head ,content ,banner结合为一个完整的视图。通常我们都是用include标签在每个jsp页面中来不断的包含各种header, style sheet, scripts and footer,现在,在site mesh的帮助下,我们可以删除他们了。下面是一个使用SiteMesh实现页面内容的简单事例(参考的是其他网络上的帖子)。需要的文件有:
sitemesh.jar
|
WEB-INF/lib
|
sitemesh-decorator.tld
|
WEB-INF
|
sitemesh-page.tld
|
WEB-INF
|
Web.xml中添加相关内容:
- <filter>
- <filter-name>sitemeshfilter-name>
- <filter-class>com.opensymphony.module.sitemesh.filter.PageFilterfilter-class>
- filter>
-
- <filter-mapping>
- <filter-name>sitemeshfilter-name>
- <url-pattern>/*url-pattern>
- filter-mapping>
-
- <taglib>
- <taglib-uri>sitemesh-decoratortaglib-uri>
- <taglib-location>/WEB-INF/sitemesh-decorator.tldtaglib-location>
- taglib>
-
- <taglib>
- <taglib-uri>sitemesh-pagetaglib-uri>
- <taglib-location>/WEB-INF/sitemesh-page.tldtaglib-location>
- taglib>
建立WEB-INF/decorators.xml描述各装饰器页面。
- <decorators defaultdir="/_decorators">
- <decorator name="main" page="main.jsp">
- <pattern>*pattern>
- decorator>
- decorators>
各标签常见属性的含义为:
- defaultdir: 包含装饰器页面的目录
- page : 页面文件名
- name : 别名
- role : 角色,用于安全
- webapp : 可以另外指定此文件存放目录
- Patterns : 匹配的路径,可以用*,那些被访问的页面需要被装饰。
建立装饰器页面 /_decorators/main.jsp
- <%@ page contentType="text/html; charset=GBK"%>
- <%@ taglib uri="sitemesh-decorator" prefix="decorator" %><html>
- <head><META HTTP-EQUIV="content-type" CONTENT="text/html; charset=gbk">
- <title><decorator:title default="装饰器页面..." />title>
- <decorator:head />
- head>
- <body> sitemesh example :Header<hr>
- <decorator:body />
- <hr>sitemesh example:Footer
- body>
- html>
- <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=gbk">解决中文问题。
建立一个的被装饰页面 /index.jsp(测试页面) :
- <%@ page contentType="text/html; charset=GBK"%>
- <html>
- <head>
- <title>Agent Testtitle>
- head> <body>
- <p>My Test Body.<p>
- >
- html>
<o:p>运行程序即可。对SiteMesh还不是很熟悉,望多指正。<o:p></o:p></o:p>
分享到:
- 2007-01-08 09:11
- 浏览 17017
- 评论(1)
- 论坛回复 / 浏览 (0 / 11318)
- 查看更多
相关推荐
SiteMesh入门学习,很好的学习总结,让你在短时间里掌握sitemesh
sitemesh入门demo。博客 Sitemesh入门和使用笔记 对应源码
sitemesh 入门教材 对初学者很有用,里边有实例 freemarker Java
struts2-sitemesh_入门收集struts2-sitemesh_入门收集
NULL 博文链接:https://cuisuqiang.iteye.com/blog/2066166
很简单的sitemesh入门教程,希望对大家有所帮助
NULL 博文链接:https://mgxy123.iteye.com/blog/1565892
web布局框架 SiteMesh教程及SiteMesh官方文档翻译
sitemesh 装饰 母版
这是SiteMesh入门级别的资料,配有一个较为全面的案例,仅供入门级别的朋友下载。
siteMesh demo siteMesh使用文档
sitemesh.jar包 sitemesh.jar 包sitemesh.jar 包sitemesh.jar包
SiteMesh是一个网页布局和装饰框架以及Web应用程序集成框架,可帮助创建由页面组成的网站,这些页面需要一致的外观,导航和布局方案。 SiteMesh会拦截对通过Web服务器请求的任何静态或动态生成的HTML页面的请求,...
sitemesh-2.2.1.jar
sitemesh 装饰页面技术.
MiddleGen-Hibernate: 本书使用版本:2.1 ... modtime=1096973436&big_mirror=0 下载文件:middlegen-2.1.zip MiddleGenIDE插件: 本书使用版本:1.2.0 ...(7)Sitemesh: ...下载文件:sitemesh-2.3.zip
sitemesh jar包sitemesh jar包sitemesh jar包sitemesh jar包sitemesh jar包sitemesh jar包sitemesh jar包
sitemesh-2.4.1.jar sitemesh-2.4.1.jar sitemesh-2.4.1.jar sitemesh-2.4.1.jar sitemesh-2.4.1.jar sitemesh-2.4.1.jar
Struts 2.0提供一个Sitemesh插件,允许在Sitemesh模板中使用Struts标记。 要使用Sitemesh需要包含Freemark,Sitemesh和Sitemesh插件库文件。 配置过滤器 如果需要使用Freemark模板文件作为装饰器文件,需要在web....
springMVC与sitemesh的结合,