教程:一分钟完成SiteMesh Template模板组合
来源:互联网 发布:c语言&.2f是什么意思 编辑:程序博客网 时间:2024/06/10 12:27
SiteMesh设计思想是,用户发送request至服务器,服务器根据此request生成动态数据,生成网页,准备返回给客户端。就在返回前,SiteMesh进行拦截,对此网页进行解析,将
title、body等部分拆解出来,套上模板后,再返回给客户端。由于SiteMesh在返回客户端的最后一步工作,此时的网页已经具备了标准的html网页格式,因此SiteMesh只需解析标
准的html网页,无需考虑各个Web应用是应用了JSP、ASP,还是Velocity技术,相当灵活。
SiteMesh使用了Decorator的设计模式。
首先要感谢发明Markdown的家伙,这东西真是好用吖!
SiteMesh概述
嗯,请自行Google之。
教程:一分钟完成Template模板组合
1.内容页面
简单的示例内容页面源代码如下:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="theme" content="basic_theme" /><title>应该是内容页面</title></head><body> <h1>Weekdays</h1> <p>5:00pm - 10:00pm</p> <p>Weekends</p> <p>5:00pm - 10:00pm</p> <a href="${pageContext.request.contextPath}/download/decorators.jsp">down</a></body></html>
在源代码中加入 <meta name="theme" content="basic_theme" />
即可由SiteMesh自动完成Template模板装配。
2.Runtime环境配置
WEB-INF目录下添加 sitemesh.xml,文件内容中除了指定 decoration-file 路径的属性需定制外,其他内容基本不需更改。
<?xml version="1.0" encoding="UTF-8"?><sitemesh> <!-- 注意这一行指定的decorators.xml文件的存放位置 --> <property name="decorators-file" value="/WEB-INF/themes/decorators.xml" /> <excludes file="${decorators-file}" /> <page-parsers> <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" /> </page-parsers> <decorator-mappers> <mapper class="com.opensymphony.module.sitemesh.mapper.PageDecoratorMapper"> <!-- 注意这一行指定<meta/>标签的 name 属性作为PageDecorator的识别符号 --> <param name="property.1" value="meta.theme" /> </mapper> <mapper class="com.opensymphony.module.sitemesh.mapper.FrameSetDecoratorMapper" /> <mapper class="com.opensymphony.module.sitemesh.mapper.PrintableDecoratorMapper"> <param name="decorator" value="printable" /> <param name="parameter.name" value="printable" /> <param name="parameter.value" value="true" /> </mapper> <mapper class="com.opensymphony.module.sitemesh.mapper.FileDecoratorMapper" /> <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper"> <param name="config" value="${decorators-file}" /> </mapper> </decorator-mappers></sitemesh>
WEB-INF/lib 目录下加入 sitemesh-2.4.2.jar
这个可以自己在github上获取最新版本,话说 sitemesh 3.0 好像无疾而终了?
WEB-INF/web.xml 文件中加入。重点是
<url-pattern>*.jsp</url-pattern>
,为了防止SiteMesh随意处理各类图片、Javascript或StyleSheets资源,最好指定后缀或url路径。<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>*.jsp</url-pattern> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> </filter-mapping>
最后也是最重要的 decorators.xml文件
<?xml version="1.0" encoding="UTF-8"?><decorators defaultdir="/WEB-INF/themes"> <decorator name="basic_theme" page="basic_theme.jsp" /></decorators>
这里的
<decorator name="basic_theme" .../>
,对应你的内容文件中的<meta name="theme" content="basic_theme" />
额外说明的是:这里使用Page模型组合Template模板,因为最简单!
<decorator-mappers> <mapper class="com.opensymphony.module.sitemesh.mapper.PageDecoratorMapper"> <param name="property.1" value="meta.theme" /> </mapper> ...
- 教程:一分钟完成SiteMesh Template模板组合
- template模板一
- SiteMesh教程
- SiteMesh教程
- SiteMesh教程
- SiteMesh教程
- SiteMesh教程
- SiteMesh教程
- Git一分钟教程
- Git一分钟教程
- git一分钟教程
- Git一分钟教程
- Git一分钟教程
- (一)函数模板与类模板 Template
- RequireJS, Sitemesh, Bootstrap 组合
- 一分钟完成MySQL5.7安装部署
- c++中的模板技术一:Function Template
- 一、 模板方法(Template Method)模式
- C语言小问题
- 联想y470p 使用Win8.1若干问题
- 习题3-40
- 2015061103 - apache httpclient jar包下载地址
- 认识自己——当断则断
- 教程:一分钟完成SiteMesh Template模板组合
- 斯坦福大学iOS开发公开课总结
- IOS-多线程
- 浅谈jsp、freemarker、velocity区别
- C Primer Plus 第五章习题
- Java Exception异常
- 服务器构架的基础1
- 子线程调用Toast报Can't create handler inside ~~~ 错误
- hiho一下 第四十九周 -题目1 : 欧拉路·一