美文网首页
Sitemesh 3 的使用及配置

Sitemesh 3 的使用及配置

作者: 短路了 | 来源:发表于2018-03-31 17:00 被阅读0次
1、Sitemesh 3 简介

Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filter。

官网:http://wiki.sitemesh.org/wiki/display/sitemesh/Home

2、Sitemesh 3 下载

这里使用Maven下载,pom.xml

<dependency>
   <groupId>org.sitemesh</groupId>
   <artifactId>sitemesh</artifactId>
   <version>3.0.0</version>
</dependency>
3、配置 Sitemesh 3 过滤器

在web.xml中添加一下过滤器

<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>
4、准备一下两个页面

webapp/demo.jsp 和 webapp/WEB-INF/views/decorators/decorator.jsp

demo.jsp - "被装饰的页面",实际要呈现的内容页

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>中文标题·</title>
</head>
<body>
    中文内容
</body>
</html>

decorator.jsp - "装饰页面",所谓的"模板页面"

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<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" />
    <br />
    <hr />
    <footer>footer</footer>
</body>
</html>
5、 添加 /WEB-INF/sitemesh3.xml
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
    <!-- 指明满足“/*”的页面,将被“/WEB-INF/views/decorators/decorator.html”所装饰 -->
    <mapping path="/*" decorator="/WEB-INF/view/decorators/decorator.jsp" />

    <!-- 指明满足“/exclude.jsp*”的页面,将被排除,不被装饰 -->
    <mapping path="/exclude.jsp*" exclue="true" />
</sitemesh>
6、运行效果
运行结果
7、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>

本文并非原创,原文地址:https://www.cnblogs.com/luotaoyeah/p/3776879.html

相关文章

  • Sitemesh 3 的使用及配置

    1、Sitemesh 3 简介 Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filt...

  • sitemesh2.4装饰器配置

    一、使用sitemesh装饰器一共需要6步1、引入sitemesh2.4 jar包2、配置web.xml3、根目录...

  • Sitemesh3 配置

    安装下载sitemesh3传送门jar包下载 使用导入下载好的jar包WebRoot\WEB-INF\lib\si...

  • sitemesh配置

    sitemesh官方地址 简介 sitemesh应用Decorator模式,用filter截取request和re...

  • 关于SiteMesh3的配置

    SiteMesh3简介 Sitemesh 是一个网页布局和修饰的框架,基于 Servlet 中的 Filter,类...

  • 使用 SiteMesh3 完善页面布局

    在网页开发中, 大部分网页都具有相同的页头, 页尾, 菜单等模块. 一般情况下我们会将这些共用的代码单独抽取成一个...

  • SpringBoot Redis缓存

    关于redis的安装、配置及启动,参考Redis简单配置使用 1.添加依赖 2.添加配置文件 3.添加配置类 Re...

  • 2018-10-26 Anaconda介绍、安装及使用教程

    Anaconda介绍、安装及使用教程 win10+python3下Anaconda的安装及环境变量配置 Windo...

  • Neovim使用

    Mac环境下安装及使用 1、安装 brew install neovim 2、启动 nvim 3、配置

  • springboot 整合 sitemesh3

    springboot 整合 sitemesh3 步骤如下:第一步: 创建WebSiteMeshFilter 类 第...

网友评论

      本文标题:Sitemesh 3 的使用及配置

      本文链接:https://www.haomeiwen.com/subject/sqzgcftx.html