1. 程式人生 > >SiteMesh2-sitemesh.xml的PageDecoratorMapper映射器的用法

SiteMesh2-sitemesh.xml的PageDecoratorMapper映射器的用法

mage play dtd git 不知道 amp str china meta

繼上一章http://www.cnblogs.com/EasonJim/p/7083165.html中使用的例子中,是通過decorators.xml文件通過URL匹配進行轉換的。

而下面這種方法是通過sitemesh.xml的PageDecoratorMapper映射器來轉換的,而無需匹配URL,只需在meta頭指定decorator中的模板即可。

下面是操作步驟:

1、在sitemesh.xml中添加PageDecoratorMapper映射器,並指定meta的名稱規則

        <mapper class="com.opensymphony.module.sitemesh.mapper.PageDecoratorMapper"
> <param name="property.1" value="meta.decorator" /> <param name="property.2" value="decorator" /> <!-- 註意這一行指定<meta/>標簽的 name 屬性作為PageDecorator的識別符號 --> <param name="property.3" value="meta.theme" /> </mapper
>

用法:

①<meta name="decorator" content="basic-theme" />

②<meta name="them" content="basic-theme" />

③<param name="property.2" value="decorator" />這個用法暫時不知道怎麽用。

註意:content指定的就是在decorators.xml文件中docorator的模板名稱。

2、在decorators.xml的模板配置還是使用原來的

<decorators defaultdir="/decorators"
> <decorator name="basic-theme" page="basic-theme.jsp"> <pattern>/data/*</pattern> </decorator> </decorators>

3、在根目錄新建index.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">
<meta name="decorator" content="basic-theme" />
<title>應該是內容頁面</title>
</head>
<body>
    <h1>Weekdays</h1>
    <p>5:00pm - 10:00pm</p>
    <p>Weekends</p>
    <p>5:00pm - 10:00pm</p>
</body>
</html>

4、測試效果如下:

技術分享

技術分享

測試工程:https://github.com/easonjim/5_java_example/tree/master/sitemesh/test2

參考:

http://wiki.sitemesh.org/wiki/display/sitemesh/Decorating+Beyond+URL+Patterns

https://my.oschina.net/yangning/blog/110487

SiteMesh2-sitemesh.xml的PageDecoratorMapper映射器的用法