SiteMesh笔记

来源:互联网 发布:知乎 高中 书包 编辑:程序博客网 时间:2024/05/17 05:08

SiteMesh是类似与Tile的一种进行页面拼装的技术,无侵入的方式。

使用方法:

1.   声明WEB-INF/decorators.xml

    定义需要装饰的页面和被装饰页面的通配符号,以及不需要装配的文件路径。

  

<?xmlversion="1.0"encoding="UTF-8"?>
<descorators>
 <!-- Excludes will never be decorated by Sitemesh. -->
  <excludes>
    <pattern>*/exclude/*</pattern>
    <pattern>/data/plaintext/*</pattern>
    <pattern>*.txt</pattern>
  </excludes>
<decorator name="basic-theme" page="basic-theme.jsp">
    <pattern>/data/*</pattern>
 
</decorators>
</decorators>

2.  定义装饰页面和分类被装饰页面

   主要是基于SiteMesh的tag来动态获取内容。


3. 在web.xml中声明siteMesh Filter.

 <filter>    <filter-name>sitemesh</filter-name>    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>  </filter>   <filter-mapping>    <filter-name>sitemesh</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapping>
4. 最后别忘记,放入sitemesh.jar 在类库中


Notice:

1. ${pageContext.request.contextPath} 基于EL来获取当前的页面context path.

2.设置页面的字符:

<%@ page contentType="text/html; charset=utf-8"%>
<METAHTTP-EQUIV="content-type"CONTENT="text/html; charset=utf-8">
<%@ page language="java"contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

总结:
顺便去看了看SiteMesh3的开发状态,很遗憾,SiteMesh3目前已经停止维护好久了。而SiteMesh2已经是2009年的版本了,目前没有后续的新版本发布。
从技术上讲,SiteMesh还是非常先进的,无侵入的设计,基于Decorator模式,相比Tiles更为容易上手。考虑到目前其已经没有后续版本的发布和维护,所以在选择页面模板的时候,还是选择了Tiles。


原创粉丝点击