Today I studied the adorner frame used in the project:Sitemesh
First look at the definition of encyclopedia: Sitemesh is a Web page layout and decoration of the framework, using it can be the content of the page and the structure of the page to separate, to achieve the purpose of sharing the page structure. The Sitemesh of the OS (Opensymphony) is a framework component used to implement page layouts and decorations (layout and decoration) in the JSP to help site developers easily separate the dynamic content and the static decorative appearance of the page.
The Sitemesh is implemented through the servlet's Fileter filter to intercept the response response. SPRINGMVC is the same in the same way, through the SPRINGMVC package filter, to achieve the filter also page.
The same point : All can improve the reuse of the common module, improve the development efficiency.
different points : include the need to use the JSP file to write dead to each JSP file, and Sitemesh is dynamic, using filter response request, and then decorate the finished page, back to the front.
The difference is still great, and we can simply understand that Sitemesh is dynamic, provides more flexibility, and the traditional include method is static, and once you need to change the public part, it's a hassle to use include.
Let's look at a simple decorator:
First, you configure the Web.xml in the
<web-app> ...
<filter>
<filter-name>sitemesh</filter-name>
<filter-class> org.sitemesh.config.configurablesitemeshfilter</filter-class>
</filter>
<filter-mapping >
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<span style= "FONT-SIZE:14PX;" ><body<decorator:getproperty property= "Body.id" writeentireproperty= "true"/><decorator: GetProperty property= "Body.class" writeentireproperty= "true"/>>
<!-- <div id= "page" > - ->
<c:if test= "${param.thirdflag!= ' 1 '}" > <jsp:include page= "/common/login-header.jsp"/>
</c:if>
<!--</div> -->
<!--<div id= "content" class= "Clearfix" >-->
<!-- <div id= "main" > -->
<decorator:body/>
<!-- </div> -->
<!-- </div> -->
<!-- <div id= "Footer" class= "Clearfix" >- >
<c:if test= "${param.thirdflag!= ' 1 '}" >
<jsp:include page= "/common/footer.jsp"/>
</c:if>
<!-- </div> -->
<!-- </div> -->
</ Body></span>
Configuration file Sitemesh.xml
<span style= "FONT-SIZE:14PX;" ><sitemesh>
<property name= "Decorators-file" value= "/web-inf/decorators.xml"/>
< Excludes file= "${decorators-file}"/>
<page-parsers>
<parser default= "true" class= Com.opensymphony.module.sitemesh.parser.FastPageParser "/>
<parser content-type=" text/html "class=" Com.opensymphony.module.sitemesh.parser.FastPageParser "/>
<parser content-type=" text/html;charset= Utf-8 "class=" Com.opensymphony.module.sitemesh.parser.FastPageParser "/>
</page-parsers>
< decorator-mappers>
<mapper class= "Com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper" >
<param name= "config" value= "${decorators-file}"/>
</mapper>
</decorator-mappers >
</sitemesh></span>
By default, Sitemesh only intercepts and decorates the Content-type in the HTTP response header for text/html types, and we typically need to expand to support more types of content-type
<mime-type>text/html</mime-type>
<mime-type>application/vnd.wap.xhtml+xml</mime-type>
<mime-type>application/xhtml+xml</mime-type>
Configuration file Decorators.xml
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?>
<decorators defaultdir="/decorators">
<excludes>
<pattern>/index.html*</pattern>
<pattern>/40*.jsp</pattern>
</excludes>
<decorator name="login-decorator" page="login-decorator.jsp">
<pattern>/signup.html</pattern>
<pattern>/findpassword/*.html</pattern>
</decorator>
<decorator name="debitcard-decorator" page="debitcard-decorator.jsp">
<pattern>/debitcard/*.html</pattern>
</decorator>
<decorator name="helpcenter-decorator" page="helpcenter-decorator.jsp">
<pattern>/helpcenterinfo/*.html</pattern>
</decorator>
<decorator name="item-decorator" page="mc-item-decorator.jsp">
<pattern>/productinfo/productItemDetail0.html*</pattern>
<pattern>/productinfo/productItemDetail*.html*</pattern>
</decorator>
<decorator name="default" page="mc-decorator.jsp">
<pattern>/*</pattern>
</decorator>
</decorators></span>
<!--The default adorner, when the following path does not match, enable the adorner for decoration-->
<mapping decorator= "/default-decorator.html"/>
<!--for different paths, enable different adorners-->
<mapping path= "/admin/*" decorator= "/another-decorator.html"/>
<mapping path= "/*.special.jsp" decorator= "/special-decorator.html"/>
<!--multiple adorners are enabled on the same path-->
<mapping>
<path>/articles/*</path>
<decorator>/decorators/article.html</decorator>
<decorator>/decorators/two-page-layout.html</decorator>
<decorator>/decorators/common.html</decorator>
</mapping>
<!--excluded, no decorated path-->
<mapping path= "/javadoc/*" exclue= "true"/>
<mapping path= "/brochures/*" exclue= "true"/>
<!--custom tag rules-->
<content-processor>
<tag-rule-bundle class= "Com.something.CssCompressingBundle"/>
<tag-rule-bundle class= "Com.something.LinkRewritingBundle"/>
</content-processor>