JSP--整合SiteMesh02

来源:互联网 发布:服务器端 语言 python 编辑:程序博客网 时间:2024/06/05 23:05

SiteMesh支持两种方法来配置,一种是XML,一种是java代码。
1 XML方式

<sitemesh>  <!-- 所有路径下的文件均由下中的文件来装饰-->  <mapping decorator="/default-decorator.html"/>  <!-- 根据路径信息配置指定的装饰文件-->  <mapping path="/admin/*" decorator="/another-decorator.html"/>  <mapping path="/*.special.jsp" decorator="/special-decorator.html"/>  <!-- 更加具体的装饰,每一个装饰文件均可装饰被装饰的文件-->  <mapping>    <path>/articles/*</path>    <decorator>/decorators/article.html</decorator>    <decorator>/decorators/two-page-layout.html</decorator>    <decorator>/decorators/common.html</decorator>  </mapping>  <!-- 不允许被被装饰的文件 -->  <mapping path="/javadoc/*" exclue="true"/>  <mapping path="/brochures/*" exclue="true"/></sitemesh>

SiteMesh默认是只拦截返回Content-Type设置为text/html的响应,可以在配置文件中配置其他类型。如下:

<sitemesh>  <mime-type>text/html</mime-type>  <mime-type>application/vnd.wap.xhtml+xml</mime-type>  <mime-type>application/xhtml+xml</mime-type>  ...</sitemesh>

2 通过java代码添加配置信息:
继承ConfigurableSiteMeshFilter,重写applyCustomConfiguration即可:

public class MySiteMeshFilter extends ConfigurableSiteMeshFilter {  @Override  protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {     builder.addDecoratorPath("/*", "/decorator.html")           .addDecoratorPath("/admin/*", "/admin/decorator.html");  }}

说明:路径下所有的文件均被decorator修饰,/admin/*下的被/admin/decorator.html修饰。