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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/396724.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

等保项目流程

等级保护&#xff1a;直属管理公安局 产品必须通过公安局安全许可证分级保护&#xff1a;直属管理保密局 产品必须通过保密局销售许可证等级保护&#xff1a;一般分为5级&#xff0c;目前最高用到是等保4级总概&#xff1a;定级——前期调研——总…

鸿蒙系统r如何升级,高歌猛进,鸿蒙系统升级机型再次确认,花粉:终等到!...

虽然华为手机现在的压力非常大&#xff0c;但是在前进的道路上&#xff0c;真的充满了乐观精神&#xff0c;而且现在也算是一路高歌猛进了&#xff0c;发展路线开始加快了许多&#xff0c;无论是新机还是系统&#xff0c;都有着非常多的新消息。因为华为手机的实力很强&#xf…

Oracle快速备份表数据

Oracle数据库中备份表数据。 例子&#xff1a; 1 create table table_name_bak as select * from table_name 1 create table table_name_bak as select * from table_name 2 where table_name.date between TO_DATE(2018-09-25,yyyy-MM-dd) and TO_DATE(2018-09-26,yyyy-MM-d…

git pull

今天在服务器上git pull是出现以下错误&#xff1a; error: Your local changes to the following files would be overwritten by merge: application/config/config.php application/controllers/home.php Please, commit your changes or stash them before you can merge. …

jq控制div是否展示_jQuery控制多个DIV的显示和隐藏

问题补充&#xff1a;这是我写的JSfunction Previous(){for(var i1;i<3;i){if(document.getElementById("d"i).style.display"block"){document.getElementById("d"(i-1)).style.display"block";}document.getElementById("d&…

C# 线程间不能调用剪切板的问题

最近做一个项目&#xff0c;需要用到线程&#xff0c;而且要用到剪切板&#xff0c;创建了一个子线程之后发现在子线程中剪切板上获取不到数据&#xff0c;当时特别纳闷&#xff0c;上网查资料&#xff0c;最后终于搞定&#xff0c;现将解决方法归纳如下&#xff1a; 第一步&am…

android studio背景模糊_[Android翻译]CameraX:过去、现在和未来的一瞥

CameraX是一个未捆绑的Android Jetpack库&#xff0c;它可以帮助你在Android应用中轻松添加摄像头功能。传统上&#xff0c;由于Android设备种类繁多&#xff0c;编程模型复杂&#xff0c;在Android上构建具有相机功能的应用程序非常困难。现在成千上万的开发者都在使用CameraX…

html页面根据分辨率缩放,html2Canvas根据不同分辨率,生成pdf内容自适应

根据屏幕大小不同&#xff0c;页面内容自适应并一页展示&#xff0c;应该如何实现// 导出页面为PDF格式import html2Canvas from html2canvasimport JsPDF from jspdfexport default{install (Vue, options) {Vue.prototype.getPdf function () {setTimeout(() > {var titl…

【agc002f】Leftmost Ball(动态规划)

【agc002f】Leftmost Ball&#xff08;动态规划&#xff09; 题面 atcoder洛谷 题解 我们从前往后依次把每个颜色按顺序来放&#xff0c;那么如果当前放的是某种颜色的第一个球&#xff0c;那么放的就会变成\(0\)号颜色&#xff0c;所以无论何时&#xff0c;\(0\)号颜色的数量不…

VS2010中的快捷键

一. VS2010中的快捷键 1&#xff1a; Ctrl Enter &#xff08;在光标指定位置的上 K C &#xff08;注释&#xff09; Ctrl E U &#xff08;取消注释&#xff09;  <>  Ctrl K U &#xff08;取消注释&#xff09; 5&#xff1a; Tab &#xff08;增加缩进&a…

export function函数传参_04 js高阶函数(惰性函数、柯里化函数、compose函数)和单例设计模式...

高阶函数的定义在《javascript设计模式和开发实践》中是这样定义的。函数可以作为参数被传递&#xff1b;函数可以作为返回值输出。结合这两个特点&#xff0c;首先想到的肯定是回调函数&#xff0c;回调函数也是高阶函数的一种&#xff0c;除了回调函数&#xff0c;还有很多的…

Javascript构造函数的继承

仅供学习参考&#xff0c;原文链接&#xff1a;http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html 今天要介绍的是&#xff0c;对象之间的"继承"的五种方法。 比如&#xff0c;现在有一个"动物"对象的构造函数。 funct…

python输入字符串str_python字符串(str)

#value "raitOrEi"#v value.capitalize()#首字母大写#print(v)#v1 v.casefold()#全部变小写&#xff0c;不只是英文的&#xff0c;其他语言特殊的大小写也变换#print(v1)#v2 v.lower()#只是英文变小写#print(v2)#设置宽度&#xff0c;并将内容居中#20 代指总长度…

html5 audio api 录音,如何使用HTML5 Web Audio API录制我的声音

在webkit浏览器上,您可以将get user media api与webkitGetUserMedia一起使用 – 如html5rocks所示.如果你想用你的声音来创建javascript事件(例如控制屏幕上的对象)你必须分析传入的声音(例如事件1的高频率 – 事件2的低频率,语音分析要复杂得多,见下文)另外,还有chrome的’x-w…

修改密码

在updateservlet.java中写了方法&#xff0c;修改用户密码&#xff0c;代码不成功求大神指教&#xff0c;代码如下&#xff1a; updateadminpw.jsp <% page contentType"text/html;charsetgb2312" pageEncoding"gb2312" %><% taglib uri"ht…

MlLib--逻辑回归笔记

批量梯度下降的逻辑回归可以参考这篇文章&#xff1a;http://blog.csdn.net/pakko/article/details/37878837 看了一些Scala语法后&#xff0c;打算看看MlLib的机器学习算法的并行化&#xff0c;那就是逻辑回归&#xff0c;找到package org.apache.spark.mllib.classification下…

mysql相关命令操作

2019独角兽企业重金招聘Python工程师标准>>> 远程连接容器中的mysql&#xff1a;mysql -h 192.168.5.116 -P 3306 -u root -p123456 启动mysql容器&#xff1a; $ sudo docker pull mysql:5.6.35 $ sudo docker run --name mysql -p 12345:3306 -e MYSQL_ROOT_PASSW…

html实体注册商标,html 注册商标,html 注册商标代码

html中注册的页面用什么标签写好对于html中的注册页面&#xff0c;策朋专业办理商标注册、专利申请、版权登记保护&#xff0c;需要一个表格。使用标签&#xff0c;输入和按钮标签来组合成就。使用html作为注册页面。实际上&#xff0c;只要您能达到期望的效果&#xff0c;它的…

java已知一个二叉树_#二叉树复习#

#二叉树复习#目录满二叉树完全二叉树平衡二叉树二叉树的主要性质--二叉树的度--二叉树的深度计算二叉树的遍历其他符号变量结点总数深度度为0的结点数/叶子结点数度为1的结点数度为2的结点数什么是满二叉树&#xff1f;二叉树每层的结点数为。满二叉树总结点数&#xff1a;。图…

hashtable - hashmap

http://www.importnew.com/24822.html转载于:https://www.cnblogs.com/qinqiu/p/9711147.html