Sitemesh 3 配置和使用(最新)
Sitemesh 3 配置和使用(最新)
一 Sitemesh简介
- Sitemesh是一个页面装饰器,可以快速的创建有统一外观Web应用 -- 导航 加 布局 的统一方案~
- Sitemesh可以拦截任何动态或则静态的HTML页面的请求,Sitemesh处理后把一个或多个装饰器组装成最后结果返回
- Sitemesh可以把一个大页面分成很多小的页面来布局

Sitemesh官网简介图片简单明了,一目了然 .. welcome Page和search Page包含两部分 Meta-Data 和 Body-Content , 通过装饰器后被装饰返回一个最终的页面 final pages.
官网 : http://wiki.sitemesh.org/wiki/display/sitemesh3/Home
二 Maven中使用Sitemesh 3
在Maven工程的Pom中添加依赖 ~
<dependency>
<groupId>org.sitemesh</groupId>
<artifactId>sitemesh</artifactId>
<version>3.0.0</version>
</dependency>
三 在web.xml中配置Sitemesh 3 拦截器
<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>
四 sitemesh 3 的配置
sitemesh 3 有两种配置方式 XML和Java
1 XML配置详解
添加一个 ~ /WEB-INF/sitemesh3.xml
<sitemesh>
<!-- 默认的装饰路径。如果没有配置其他的路径将启用默认路径,这个可以适用于所有路径 -->
<!-- Map default decorator. This shall be applied to all paths if no other paths match. -->
<mapping decorator="/default-decorator.html"/>
<!-- 配置装饰器的路径 -->
<!-- Map decorators to path patterns. -->
<mapping path="/admin/*" decorator="/another-decorator.html"/>
<mapping path="/*.special.jsp" decorator="/special-decorator.html"/>
<!-- 对同一路径配置多个装饰器 -->
<!-- Alternative convention. This is more verbose but allows multiple decorators
to be applied to a single path. -->
<mapping>
<path>/articles/*</path>
<decorator>/decorators/article.html</decorator>
<decorator>/decorators/two-page-layout.html</decorator>
<decorator>/decorators/common.html</decorator>
</mapping>
<!-- 配置 不被装饰 的路径 -->
<!-- Exclude path from decoration. -->
<mapping path="/javadoc/*" exclue="true"/>
<mapping path="/brochures/*" exclue="true"/>
<!-- 默认情况下,
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>
<!--
Sitemesh 3 默认只提供了 body,title,head 种 tag 类型
我们可以添加自定义的tag规则 -->
<content-processor>
<tag-rule-bundle class="com.something.CssCompressingBundle" />
<tag-rule-bundle class="com.something.LinkRewritingBundle"/>
</content-processor>
</sitemesh>
4 Java的配置方式
package com.erma.common;
import org.sitemesh.builder.SiteMeshFilterBuilder;
import org.sitemesh.config.ConfigurableSiteMeshFilter;
/**
* Created by Erma on 2017/4/13.
*/
public class MySiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
// 默认的装饰器
// Map default decorator. This shall be applied to all paths if no other paths match.
builder.addDecoratorPath("/*", "/default-decorator.html")
// 配合 自己 的 路径对应的装饰器
// Map decorators to path patterns.
.addDecoratorPath("/admin/*", "/another-decorator.html")
.addDecoratorPath("/*.special.jsp", "/special-decorator.html")
//一个路径多个装饰器
// Map multiple decorators to the a single path.
.addDecoratorPaths("/articles/*", "/decorators/article.html",
"/decoratos/two-page-layout.html",
"/decorators/common.html")
// 配置不被装饰的路径
// Exclude path from decoration.
.addExcludedPath("/javadoc/*")
.addExcludedPath("/brochures/*");
// 配置自己的MineType
builder.setMimeTypes("text/html", "application/xhtml+xml", "application/vnd.wap.xhtml+xml");
// 配置自己的tag
builder.addTagRuleBundles(new CssCompressingBundle(), new LinkRewritingBundle());
}
}
五 Sitemesh 3 的使用
下面是使用 intellij + Maven + Sitemsehxml的配置方式的一个使用
1 配置Maven的pom 和web.xml按照上面的方式
2 配置sitemseh.xml
<sitemesh>
<!-- 拦截任何路径配置装饰器 -->
<mapping path="/*" decorator="/WEB-INF/jsp/layouts/decorator.jsp"/>
<!-- 这里配置自定义的tag -->
<content-processor>
<tag-rule-bundle class="com.erma.common.MySiteMeshFilter"/>
</content-processor>
</sitemesh>
3 配置自定义的tag
package com.erma.common;
import org.sitemesh.SiteMeshContext;
import org.sitemesh.content.ContentProperty;
import org.sitemesh.content.tagrules.TagRuleBundle;
import org.sitemesh.content.tagrules.html.ExportTagToContentRule;
import org.sitemesh.tagprocessor.State;
/**
* Created by Erma on 2017/4/13.
*/
public class MySiteMeshFilter implements TagRuleBundle {
public void install(State state, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
state.addRule("myTag", new ExportTagToContentRule(siteMeshContext,contentProperty.getChild("myTag"),false));
}
public void cleanUp(State state, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
}
}
4 配置模板
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>
<sitemesh:write property='title'/>
</title>
<sitemesh:write property='head'/>
</head>
<body>
我是装饰器 : title的内容在这里 ~ <sitemesh:write property='title'/><br/>
我是装饰器 : body的内容在这里 ~ <sitemesh:write property='body'/><br/>
我是装饰器 : myTag的内容在这里 ~ <sitemesh:write property='myTag'/><br/>
</body>
</html>
5 home.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>我是标题~</title>
</head>
<body>
<myTag>
我是自定义的tag
</myTag>
嗨喽嗨喽 ~
</body>
</html>
6 效果

Sitemesh 3 配置和使用(最新)的更多相关文章
- Cassandra概念学习系列之Windows里下载且安装配置Cassandra(最新的3.11.1版本)(图文详解)
不多说,直接上干货! 最近我开始在windows环境中使用Cassandra,虽然在Cassandra站点的安装命令非常清楚和精简,我仍然在环境配置上遇到一些问题.所以我想为后来者分享下我的经验. ...
- SpringBoot第二集:注解与配置(2020最新最易懂)
2020最新SpringBoot第二集:基础注解/基础配置(2020最新最易懂) 一.Eclipse安装SpringBoot插件 Eclipse实现SpringBoot开发,为便于项目的快速构建,需要 ...
- mongodb 3.0下载安装、配置及mongodb最新特性、基本命令教程详细介绍
mongoDB简介(本文由www.169it.com搜集整理) MongoDB是一个高性能,开源,无模式的文档型数据库,是目前在IT行业非常流行的一种非关系型数据库(NoSql).它在许多场景下可用于 ...
- 为pc编译配置安装当前最新的内核
搜索公众号:itxxgh (IT学习干货),全公益.免费.定期,提供,<IT学习教程>.不会骚扰大家,仅仅需轻点关注,也会传播<中华传统文化>传播正能量. 或扫描二维码 1 ...
- 配置友盟最新SDK遇到的问题
编译报错 Undefined symbols for architecture i386:原因:i386是代表模拟器,显示i386错误说明静态库不支持模拟器,只支持真机.友盟最新SDK可能不支持模拟 ...
- 配置Orchard Core 最新的包资源
添加预览包源 在本文中,我们将添加一个指向预览包的新包源. 与从主分支构建的NuGet上的代码相比,每次在dev分支上提交一些代码时都会构建预览包. 它们是最新的版本,但不是最稳定的,可以包含突破性的 ...
- JDK下载安装与环境变量配置【全网最新】
1.下载安装JDK 下载地址:(https://www.oracle.com/java/technologies/downloads/) 最好选择解压版,解压即可(说删就删) 解压:例如我解压目录为 ...
- 使用 sitemesh/decorator装饰器装饰jsp页面(原理及详细配置)
摘要:首先这个Decorator解释一下这个单词:“装饰器”,我觉得其实可以这样理解,他就像我们用到的Frame,他把每个页面共有的东西提炼了出来,也可能我们也会用各种各样的include标签,将我们 ...
- SiteMesh在项目中的配置
SiteMesh在项目中的配置 首先在web.xml里面增加siteMesh的配置: <filter> <filter-name>sitemesh</filter-nam ...
随机推荐
- JS排序算法
1.冒泡排序 冒泡算法是比较相邻的两项,如果前者比后者大,就交换他们. 假设一共有n项,那么一共需要n-1趟,第一趟需要交换n-1次,但是第一趟结束后,最后一项基本确定就是最大项了,所以第二次需要交换 ...
- 关于Storm tick
关于Storm tick 1. tick的功能 Apache Storm中内置了一种定时机制——tick,它能够让任何bolt的所有task每隔一段时间(精确到秒级,用户可以自定义)收到一个来自__s ...
- YARN学习笔记(一)——YARN的简介
YARN的简介 什么是YARN MRv1的架构和缺陷 经典MapReduce的局限性 解决可伸缩性问题 YARN的架构 一个可运行任何分布式应用程序的集群 YARN中的应用程序提交 YARN的其他特性 ...
- TypeScript设计模式之策略、模板方法
看看用TypeScript怎样实现常见的设计模式,顺便复习一下. 学模式最重要的不是记UML,而是知道什么模式可以解决什么样的问题,在做项目时碰到问题可以想到用哪个模式可以解决,UML忘了可以查,思想 ...
- Java数据类型及其转换&&经常用到的快捷键
数据类型 基本数据类型分类 (8种) byte .short. int. long. char. float. double .boolean 1个字节占8位 整数型byte 1字节 -128~1 ...
- MySQL常用函数及日期
一.数学函数 数学函数主要用于处理数字,包括整型.浮点数等. ABS(x) 返回x的绝对值 SELECT ABS(-1) -- 返回1 CEIL(x),CEILING(x) 返回大于或等于x的最小整数 ...
- python rsa 加密解密 (编解码,base64编解码)
最近有需求,需要研究一下RSA加密解密安全:在网上百度了一下例子文章,很少有文章介绍怎么保存.传输.打印加密后的文本信息,都是千篇一律的.直接在一个脚本,加密后的文本信息赋于变量,然后立马调用解密.仔 ...
- JAVA基础知识(2)--关键字final的使用
/***Final关键字的使用*@author lihaiming*Email:912547587@qq.com*关键字Final可以修饰属性,方法,类*修饰属性的时候,final修饰的变量是一个常量 ...
- (29)网络编程之TCP通信协议
TCP通信协议特点: 1.tcp协议是基于IO流进行数据的传输,是面向链接的. 2.tcp进行数据传输的时候,数据没有大小限制的. 3.面向链接,通过三次握手的机制,保证数据的完整性,是一个可靠的协议 ...
- 使用javascript解一道关于会议日程安排的面试题
这道面试题是从 HarrisonHao 的一篇博文中看到的:原文链接 我看到之后,感觉此题十分有趣,遂自己用 node.js 以不同的思路实现了一遍,实现中使用了 lodash 原题比较长,而且是英文 ...