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

來源:互聯網
上載者:User

標籤:target   hub   isp   https   app   theme   UI   param   oct   

繼上一章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映射器的用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.