Sitemesh 自定义decorators.xml 文件路径

来源:互联网 发布:js apply的z作用 编辑:程序博客网 时间:2024/06/07 09:02


实现思路: 通过覆盖默认的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 文件.


帮助别人,提升自己.