zoukankan      html  css  js  c++  java
  • SiteMesh2-sitemesh.xml的PageDecoratorMapper映射器的用法

    继上一章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、测试效果如下:

    5、<param name="property.2" value="decorator" />的用法

    ①新建test.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 decorator="basic-theme">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    </head>
    <body>
        <h1>Test</h1>
    </body>
    </html>

    ②直接访问test.jsp页面,得到的效果就是使用了模板页面的,效果如下:

    测试工程: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

    https://web.archive.org/web/20071008180624/http://www.opensymphony.com/sitemesh/api/com/opensymphony/module/sitemesh/mapper/PageDecoratorMapper.html

  • 相关阅读:
    主机连接不上虚拟机或虚拟机桥接没有网络
    asp web 报表
    heart or house?
    CPointer
    Raid
    Dos for by 随风
    不支持uri格式
    FabEdge V0.4 新特性:支持多集群通讯
    运维监控
    /etc缩写
  • 原文地址:https://www.cnblogs.com/EasonJim/p/7086916.html
Copyright © 2011-2022 走看看