1. Sitemesh是一个网页布局和修饰的框架,基于Servlet中的 Filter,类似于 ASP.NET 中的‘母版页’技术。相关类似技术:Apache Tiles。 官网:http://wiki.sitemesh.org/wiki/display/sitemesh/Home 。
  2. 下载
    ① GitHub 地址:https://github.com/sitemesh/sitemesh3
    ② maven:
<dependency><groupId>org.sitemesh</groupId><artifactId>sitemesh</artifactId><version>3.0.0</version>
</dependency>

3 . 配置 Sitemesh 3 过滤器
在 web.xml 中添加 Sitemesh Filter

<web-app>...<filter><filter-name>sitemesh</filter-name><filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class></filter><filter-mapping><filter-name>sitemesh</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
  1. 准备两个页面:demo.html 和 decorator.html
    ① demo.html - “被装饰的页面”,实际要呈现的内容页。
<!DOCTYPE html>
<html>
<head><title>内容页的标题</title>
</head>
<body>内容页的body部分
</body>
</html>

② decorator.html - “装饰页面”,所谓的“母版页”。

<!DOCTYPE html>
<html>
<head>
<title><sitemesh:write property='title' /> - ltcms
</title>
<sitemesh:write property='head' />
</head>
<body><header>header</header><hr />demo.html的title将被填充到这儿:<sitemesh:write property='title' /><br />demo.html的body将被填充到这儿:<sitemesh:write property='body' /><hr /><footer>footer</footer>
</body>
</html>
  1. 添加 /WEB-INF/sitemesh3.xml
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh><!-- 指明满足“/*”的页面,将被“/WEB-INF/views/decorators/decorator.html”所装饰 --><mapping path="/*" decorator="/WEB-INF/views/decorators/decorator.html" /><!-- 指明满足“/exclude.jsp*”的页面,将被排除,不被装饰 --><mapping path="/exclude.jsp*" exclue="true" />
</sitemesh>
  1. 访问
    访问 demo.html 页面,实际效果如下:
  • sitemesh3.xml 配置详解
<sitemesh><!--默认情况下,sitemesh 只对 HTTP 响应头中 Content-Type 为 text/html 的类型进行拦截和装饰,我们可以添加更多的 mime 类型--><mime-type>text/html</mime-type><mime-type>application/vnd.wap.xhtml+xml</mime-type><mime-type>application/xhtml+xml</mime-type>...<!-- 默认装饰器,当下面的路径都不匹配时,启用该装饰器进行装饰 --><mapping decorator="/default-decorator.html"/><!-- 对不同的路径,启用不同的装饰器 --><mapping path="/admin/*" decorator="/another-decorator.html"/><mapping path="/*.special.jsp" decorator="/special-decorator.html"/><!-- 对同一路径,启用多个装饰器 --><mapping><path>/articles/*</path><decorator>/decorators/article.html</decorator><decorator>/decorators/two-page-layout.html</decorator><decorator>/decorators/common.html</decorator></mapping><!-- 排除,不进行装饰的路径 --><mapping path="/javadoc/*" exclue="true"/><mapping path="/brochures/*" exclue="true"/><!-- 自定义 tag 规则 --><content-processor><tag-rule-bundle class="com.something.CssCompressingBundle" /><tag-rule-bundle class="com.something.LinkRewritingBundle"/></content-processor>...</sitemesh>
  • 自定义 tag 规则
    Sitemesh 3 默认只提供了 body,title,head 等 tag 类型,我们可以通过实现 TagRuleBundle 扩展自定义的 tag 规则:
public class MyTagRuleBundle implements TagRuleBundle {@Overridepublic void install(State defaultState, ContentProperty contentProperty,SiteMeshContext siteMeshContext) {defaultState.addRule("myHeader", new ExportTagToContentRule(contentProperty.getChild("myHeader"), false));}@Overridepublic void cleanUp(State defaultState, ContentProperty contentProperty,SiteMeshContext siteMeshContext) {}
}

最后在 sitemesh3.xml 中配置即可:

 <content-processor><tag-rule-bundle class="com.lt.common.ext.sitemesh3.MyTagRuleBundle" /></content-processor>

Sitemesh3使用及配置相关推荐

  1. sitemesh3.0的配置以及在静态html中的使用

    sitemesh3配置.md 引言 白天的时候一直想使用sitemesh来整合spring mvc+velocity+mybatis架构,但是在度娘搜了很久都没搜到想要的资料,同时sitemesh官网 ...

  2. Sitemesh3的使用及配置

    1 . Sitemesh 3 简介 Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filter,类似于 ASP.NET 中的'母版页'技术.参考:百度百科,相关类似技术:A ...

  3. Sitemesh 3 的使用及配置

    1 . Sitemesh 3 简介 Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filter,类似于 ASP.NET 中的'母版页'技术.参考:百度百科,相关类似技术:A ...

  4. SiteMesh3的基本使用

    Sitemesh是一个网页布局和修饰的开源框架,利用它可以将网页的内容和页面结构分离,用以达到页面结构共享的目的,类似于ASP.NET的"母版页"技术. Sitemesh是基于se ...

  5. nginx配置http、https访问,nginx指定ssl证书,阿里云腾讯云华为云设置nginx https安全访问

    nginx配置http.https访问 要设置https访问需要从对应的云厂商申请证书,并下载Nginx证书到服务器. 我这里从阿里云申请了免费的域名证书,然后将证书放置在服务器的/etc/ssl/. ...

  6. 在kotlin companion object中读取spring boot配置文件,静态类使用@Value注解配置

    在kotlin companion object中读取配置文件 静态类使用@Value注解配置 class Config {@Value("\${name}")fun setNam ...

  7. 大数据学习01——配置虚拟机节点相关网络

    1.配置mac地址和ip (1)更改适配器设置 找到这个后开始设置windows中的网络连接 (2)接着对三台虚拟机的mac地址和ip进行设置 1.mac地址设置 进入linux节点中的这个位置进行设 ...

  8. plsql配置多数据源,想换哪个换哪个

    现在的公司内部普遍使用plsql对数据库进行管理.而数据库非常多,从测试到线上环境数据库那么多,我们通常使用同一配置管理,便于切换.那么配置数据库连接就成为了很重要的一步. 1.安装plsql (这里 ...

  9. Linux下docker安装配置oracle,oracle创建用户并远程连接,实测可用!

    最近在给同学弄毕业设计的数据库,因为oracle在个人电脑上极不稳定,所以他的电脑数据库崩溃了,这时候我就在docker上为他拉了一个oracle,解决了问题. docker的安装共有以下几步,实测没 ...

最新文章

  1. stringbuilder 拼接语句缺失右括号_Leetcode No.22 括号生成
  2. adv7842自定义方式
  3. 读取资源文件的工具.
  4. ML之监督学习算法之分类算法一 ———— k-近邻算法(最邻近算法)
  5. 兵家必争之地!爱尔兰是如何成为物联网的先锋?
  6. Java获取文件大小,文件夹内文件个数的工具类
  7. curl循环监控_阿里巴巴开源性能监控神器Arthas
  8. 文件包含——php伪协议(五)
  9. 3706 teradata 语句报错_Teradata SQL
  10. JavaScript 中的string 方法
  11. (124)FPGA面试题-ZYNQ的PS和PL端怎么交互的?
  12. 随想录(C++下多线程的创建)
  13. Delphi 7生成XML
  14. CUDA学习(二十九)
  15. L1-027 出租 (20 分)—团体程序设计天梯赛
  16. 无法使用prop_Adobe Launch配置流量变量(Prop)
  17. 《深入浅出数据分析》笔记一
  18. Panoramic Imaging及其应用于场景理解的综述
  19. Flash Player For Android
  20. IPD需求和市场管理流程

热门文章

  1. 设计原则 —— 针对接口编程而不针对实现编程
  2. 新技能 get —— 五笔打字
  3. EPI_H/EPI_V(边缘保持指数,matlab 矢量化编程)
  4. Java 原生数据类型、Integer
  5. UNIX 环境高级编程(一) apue.h 文件与apue.3e的安装
  6. 使用 IDEA 创建 Scala 工程
  7. 机器学习基础(二十一)—— 分类与回归、生成模型与判别模型
  8. java 控制台输出到gui_java – 如何将类似窗口的“控制台”添加到GUI?
  9. Android 自定义控件圆形图案
  10. 为什么都建议学java而不是python-为什么java比python复杂,还是有很多人选择学习java?...