Sitemesh 自定義decorators.xml 文件路徑

實現思路: 經過覆蓋默認的sitemesh.xml來實現 html

1. 打開sitemesh的jar文件, 在com.opensymphony.module.sitemesh.factory目錄裏找到sitemesh-default.xml, java

將其複製到項目的任意目錄(如/commons/sitemsh/目錄), 並將其更名爲sitemesh.xml; web


2. 在web.xml文件裏添加一個容器參數sitemesh.configfile,值爲sitemesh.xml的項目路徑. 具體以下: spa

<context-param>
        <param-name>sitemesh.configfile</param-name>
        <param-value>/commons/sitemesh/sitemesh.xml</param-value>
    </context-param>
3.修改sitemesh.xml中屬性爲decorators-file的value值,根據decorators.xml 文件所在的項目路徑來修改(如decorators.xml 位於/commons/sitemesh目錄),其他配置保持不變.,具體以下:

<sitemesh>
    <property name="decorators-file" value="/commons/sitemesh/decorators.xml"/>
    <excludes file="${decorators-file}"/>

    <page-parsers>
        <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/>
    </page-parsers>
4. 經過以上設置也就完成了自定義decorators.xml 文件路徑 的功能.


更多信息請參考sitemesh 源碼中的 DefaultFactory.java 文件. code


幫助別人,提高本身. xml

相關文章
相關標籤/搜索