Sitemesh 自定義decorators.xml 文件路徑


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

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

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


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

    <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 文件.


幫助別人,提升自己.


發佈了57 篇原創文章 · 獲贊 102 · 訪問量 59萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章