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

相关文章
相关标签/搜索