Sitemesh3的使用及配置
1 . Sitemesh 3 简介
Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filter,类似于 ASP.NET 中的‘母版页’技术。参考:百度百科,相关类似技术:Apache Tiles。
官网:http://wiki.sitemesh.org/wiki/display/sitemesh/Home 。
2 . Sitemesh 3 下载
最新版本:3.0.0-SNAPSHOT
① GitHub 地址:https://github.com/sitemesh/sitemesh3
② maven:
1 <dependency> 2 <groupId>org.sitemesh</groupId> 3 <artifactId>sitemesh</artifactId> 4 <version>3.0.0</version> 5 </dependency>
3 . 配置 Sitemesh 3 过滤器
在 web.xml 中添加 Sitemesh Filter:
1 <web-app> 2 3 ... 4 5 <filter> 6 <filter-name>sitemesh</filter-name> 7 <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class> 8 </filter> 9 <filter-mapping> 10 <filter-name>sitemesh</filter-name> 11 <url-pattern>/*</url-pattern> 12 </filter-mapping> 13 14 </web-app>
4 . 准备两个页面:demo.html 和 decorator.html
① demo.html - “被装饰的页面”,实际要呈现的内容页。
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>内容页的标题</title> 5 </head> 6 <body> 7 内容页的body部分 8 </body> 9 </html>
② decorator.html - “装饰页面”,所谓的“母版页”。
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 <sitemesh:write property='title' /> - ltcms 6 </title> 7 <sitemesh:write property='head' /> 8 </head> 9 <body> 10 <header>header</header> 11 <hr /> 12 demo.html的title将被填充到这儿: 13 <sitemesh:write property='title' /><br /> 14 demo.html的body将被填充到这儿: 15 <sitemesh:write property='body' /> 16 <hr /> 17 <footer>footer</footer> 18 </body> 19 </html>
5 . 添加 /WEB-INF/sitemesh3.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <sitemesh> 3 <!-- 指明满足“/*”的页面,将被“/WEB-INF/views/decorators/decorator.html”所装饰 --> 4 <mapping path="/*" decorator="/WEB-INF/views/decorators/decorator.html" /> 5 6 <!-- 指明满足“/exclude.jsp*”的页面,将被排除,不被装饰 --> 7 <mapping path="/exclude.jsp*" exclue="true" /> 8 </sitemesh>
6 . 运行效果
访问 demo.html 页面,实际效果如下:
7 . sitemesh3.xml 配置详解
1 <sitemesh> 2 <!--默认情况下, 3 sitemesh 只对 HTTP 响应头中 Content-Type 为 text/html 的类型进行拦截和装饰, 4 我们可以添加更多的 mime 类型--> 5 <mime-type>text/html</mime-type> 6 <mime-type>application/vnd.wap.xhtml+xml</mime-type> 7 <mime-type>application/xhtml+xml</mime-type> 8 ... 9 10 <!-- 默认装饰器,当下面的路径都不匹配时,启用该装饰器进行装饰 --> 11 <mapping decorator="/default-decorator.html"/> 12 13 <!-- 对不同的路径,启用不同的装饰器 --> 14 <mapping path="/admin/*" decorator="/another-decorator.html"/> 15 <mapping path="/*.special.jsp" decorator="/special-decorator.html"/> 16 17 <!-- 对同一路径,启用多个装饰器 --> 18 <mapping> 19 <path>/articles/*</path> 20 <decorator>/decorators/article.html</decorator> 21 <decorator>/decorators/two-page-layout.html</decorator> 22 <decorator>/decorators/common.html</decorator> 23 </mapping> 24 25 <!-- 排除,不进行装饰的路径 --> 26 <mapping path="/javadoc/*" exclue="true"/> 27 <mapping path="/brochures/*" exclue="true"/> 28 29 <!-- 自定义 tag 规则 --> 30 <content-processor> 31 <tag-rule-bundle class="com.something.CssCompressingBundle" /> 32 <tag-rule-bundle class="com.something.LinkRewritingBundle"/> 33 </content-processor> 34 ... 35 36 </sitemesh>
8 . 自定义 tag 规则
Sitemesh 3 默认只提供了 body,title,head 等 tag 类型,我们可以通过实现 TagRuleBundle 扩展自定义的 tag 规则:
1 public class MyTagRuleBundle implements TagRuleBundle { 2 @Override 3 public void install(State defaultState, ContentProperty contentProperty, 4 SiteMeshContext siteMeshContext) { 5 defaultState.addRule("myHeader", new ExportTagToContentRule(contentProperty.getChild("myHeader"), false)); 6 7 } 8 9 @Override 10 public void cleanUp(State defaultState, ContentProperty contentProperty, 11 SiteMeshContext siteMeshContext) { 12 } 13 }
最后在 sitemesh3.xml 中配置即可:
1 <content-processor> 2 <tag-rule-bundle class="com.lt.common.ext.sitemesh3.MyTagRuleBundle" /> 3 </content-processor>
转载于:https://www.cnblogs.com/duyinqiang/p/5237549.html
Sitemesh3的使用及配置相关推荐
- sitemesh3.0的配置以及在静态html中的使用
sitemesh3配置.md 引言 白天的时候一直想使用sitemesh来整合spring mvc+velocity+mybatis架构,但是在度娘搜了很久都没搜到想要的资料,同时sitemesh官网 ...
- Sitemesh3使用及配置
Sitemesh是一个网页布局和修饰的框架,基于Servlet中的 Filter,类似于 ASP.NET 中的'母版页'技术.相关类似技术:Apache Tiles. 官网:http://wiki.s ...
- Sitemesh 3 的使用及配置
1 . Sitemesh 3 简介 Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filter,类似于 ASP.NET 中的'母版页'技术.参考:百度百科,相关类似技术:A ...
- SiteMesh3的基本使用
Sitemesh是一个网页布局和修饰的开源框架,利用它可以将网页的内容和页面结构分离,用以达到页面结构共享的目的,类似于ASP.NET的"母版页"技术. Sitemesh是基于se ...
- nginx配置http、https访问,nginx指定ssl证书,阿里云腾讯云华为云设置nginx https安全访问
nginx配置http.https访问 要设置https访问需要从对应的云厂商申请证书,并下载Nginx证书到服务器. 我这里从阿里云申请了免费的域名证书,然后将证书放置在服务器的/etc/ssl/. ...
- 在kotlin companion object中读取spring boot配置文件,静态类使用@Value注解配置
在kotlin companion object中读取配置文件 静态类使用@Value注解配置 class Config {@Value("\${name}")fun setNam ...
- 大数据学习01——配置虚拟机节点相关网络
1.配置mac地址和ip (1)更改适配器设置 找到这个后开始设置windows中的网络连接 (2)接着对三台虚拟机的mac地址和ip进行设置 1.mac地址设置 进入linux节点中的这个位置进行设 ...
- plsql配置多数据源,想换哪个换哪个
现在的公司内部普遍使用plsql对数据库进行管理.而数据库非常多,从测试到线上环境数据库那么多,我们通常使用同一配置管理,便于切换.那么配置数据库连接就成为了很重要的一步. 1.安装plsql (这里 ...
- Linux下docker安装配置oracle,oracle创建用户并远程连接,实测可用!
最近在给同学弄毕业设计的数据库,因为oracle在个人电脑上极不稳定,所以他的电脑数据库崩溃了,这时候我就在docker上为他拉了一个oracle,解决了问题. docker的安装共有以下几步,实测没 ...
最新文章
- python是什么公司开发的软件-软件开发|什么是行为驱动的 Python?
- wxWidgets:wxMiniFrame类用法
- face3000 c++ 代码运行
- 关于陀螺仪 deviceorientation
- 数据架构总体设计方案
- 如何使用Github实现协同工作(例子:两人合作写代码)
- 物联网专业要学c语言吗,物联网应用技术专业是文科还是理科
- 【CGAL_多面体】3D多面体表面
- 微信群发图文消息步骤说明
- Qt调试错误:The inferior stopped because it received a signal from the Operating System.SIGSEGV
- IT是什么意思:it是信息技术领域的统称
- python barrier_Python中的Barrier对象
- action='store_true'
- android 空间动态,Android手机QQ空间新版:玩转GIF动态说说
- 微信公众号中h5页面扫一扫实现
- java出现404的原因是_关于出现404错误的原因
- 基于 树莓派4 + STM32H7 构建支持云端应用的嵌入式系统平台 【一】
- 区块链开发(一)Windows平台搭建基于以太坊的区块链开发环境
- Nginx之父被抓,在职期间写的nginx竟属于公司?
- CSS权重的问题:选择器权重值的计算
热门文章
- d3 i5 神舟精盾k480n_6款神舟精盾轻薄记本发布,10nm十代酷睿,匠心打造国潮好本...
- ldap统一用户认证php,针对LDAP服务器进行身份认证
- 453. 最小操作次数使数组元素相等
- a频繁连接不上redis_连接不到redis Caused by:..._慕课问答
- 什么是Java文件?
- c语言字符常量和字符串常量_C语言中的字符常量
- 开源软件 许可证密钥_自由和开源软件-1中的重要许可证
- 五、规则组织的衍生组织——纬山形组织数学模型的建立
- 04-图像的形状绘制
- C++---汉明距离