关于sitemesh装饰器的使用方式

decorator.xml 放在WEB-INF下面

<?xml version="1.0" encoding="UTF-8"?>

<decorators defaultdir="/WEB-INF/freemarker/decorators">
    <excludes>
        <pattern>/login.*</pattern>
        <pattern>/css/*</pattern>
        <pattern>/images/*</pattern>
        <pattern>/js/*</pattern>
        <pattern>/ajax/*</pattern>
        <pattern>**/ajax/*</pattern>
        <pattern>/*.jsp</pattern>
        <pattern>**/json*</pattern>
        <pattern>**/iframe/*</pattern>
        <pattern>*.do</pattern>
    </excludes>
    <decorator name="main" page="main.ftl">
        <pattern>*.htm*</pattern>
        <!-- <pattern>/*</pattern> -->
    </decorator>

</decorators>

sitemesh.xml 放在WEB-INF下面

<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
    <property name="decorators-file" value="/WEB-INF/decorators.xml" />
    <excludes file="${decorators-file}" />

    <page-parsers>
        <parser default="true"
            class="com.opensymphony.module.sitemesh.parser.DefaultPageParser" />
        <parser content-type="text/html"
            class="com.opensymphony.module.sitemesh.parser.FastPageParser" />
        <parser content-type="text/html;charset=UTF-8"
            class="com.opensymphony.module.sitemesh.parser.FastPageParser" />
    </page-parsers>

    <decorator-mappers>

        <mapper class="com.opensymphony.module.sitemesh.mapper.PageDecoratorMapper">
            <param name="property.1" value="meta.decorator" />
            <param name="property.2" value="decorator" />
        </mapper>

        <mapper
            class="com.opensymphony.module.sitemesh.mapper.FrameSetDecoratorMapper">
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.AgentDecoratorMapper">
            <param name="match.MSIE" value="ie" />
            <param name="match.Mozilla/" value="ns" />
            <param name="match.Opera" value="opera" />
            <param name="match.Lynx" value="lynx" />
        </mapper>

        <mapper
            class="com.opensymphony.module.sitemesh.mapper.PrintableDecoratorMapper">
            <param name="decorator" value="printable" />
            <param name="parameter.name" value="printable" />
            <param name="parameter.value" value="true" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.RobotDecoratorMapper">
            <param name="decorator" value="robot" />
        </mapper>

        <mapper
            class="com.opensymphony.module.sitemesh.mapper.ParameterDecoratorMapper">
            <param name="decorator.parameter" value="decorator" />
            <param name="parameter.name" value="confirm" />
            <param name="parameter.value" value="true" />
        </mapper>

        <mapper class="com.opensymphony.module.sitemesh.mapper.FileDecoratorMapper">
        </mapper>

        <mapper
            class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
            <param name="config" value="${decorators-file}" />
        </mapper>

    </decorator-mappers>
</sitemesh>

web.xml

<!-- sitemesh freemarker -->
    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>sitemesh-freemarker</servlet-name>
        <servlet-class>com.suning.framework.web.sitemesh.SitemeshFreemarkerDecoratorServlet</servlet-class>
        <init-param>
            <param-name>TemplatePath</param-name>
            <param-value>/</param-value>
        </init-param>
        <init-param>
            <param-name>NoCache</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>default_encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>sitemesh-freemarker</servlet-name>
        <url-pattern>*.ftl</url-pattern>
    </servlet-mapping>

装饰器文件的写法 main.ftl

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"  pageEncoding="UTF-8" />
    <title>XX系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <meta content="" name="description"/>
    <meta content="" name="author"/>
    <meta name="MobileOptimized" content="320">
<#include "../common/commonCss.ftl">
<#include "../common/commonJs.ftl">
</head>

<body class="no-skin">
    <!-- top frame -->
    <#--include "../common/header.ftl"-->

    <#--div class="main-container" id="main-container"-->
        <!-- sidebar menu -->
        <#--include "../common/sideBar.ftl"-->

        <#--div class="main-content">
            <div class="main-content-inner">
                <div class="page-content"-->
                    ${body}
                <#--/div>
            </div>
        </div-->

        <!-- footer -->
        <#--include "../common/footer.ftl"-->

        <!-- scroll -->
        <#--a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse"--> 
            <#--i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
        </a>
    </div>

    <div class="modal fade" id="basic" tabindex="-1" role="basic" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content" style="overflow:auto; zoom:1;">
          <div class="modal-body"><img src="${base}/sdipapos/avatars/user.gif" height="60" style="float:left; margin-left:20px;"> <h4 class="modal-title" style="float:left; margin-left:20px;"></h4></div>
        </div>
      </div>
    </div-->
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值