Create a composite view using sitemesh-2. decorator

Source: Internet
Author: User
Decorator concept
To build reusable web applications, a common method is to build a hierarchical system, just like the following common web application:
Front end, front-end: JSP and Servlets, or jakarta's velocity
Control layer framework Controller: (Struts/Webwork)
Business logic: Main Business logic
Persistence framework: hibernate/jdo
However, the front-end page logic is hard to be reused. When you use an endless number of include to reuse public headers, stylesheet, scripts, and footer on each page, A problem occurs-repeated code. Each page must use copy to reuse the page structure,
When you need to change the page structure creatively, the disaster will fall in love with you.
Sitemesh uses filter to intercept request and response, and adds decoration (possibly header, footer...) to the original page ...), then return the result to the client, and the decorated original page does not know the decoration of sitemesh, which achieves decoupling.
It is said that the new Portlet specification will help us to implement more cool ideas than these, but I still don't know what it is, anyone interested can study
Jetspeed, or JSR (Java Specification Request) 168, but I think sitemesh is so simple that we should use it first.

Let's see how to configure the environment
In addition to the sitemesh. jar in the WEB-INF/lib to copy to the WEB-INF in the sitemesh-decorator.tld, the sitemesh-page.tld file, there are 2 files to build to the WEB-INF /:
Sitemesh. xml (optional)
Decorators. xml
Sitemesh. xml can be configured with two types of information:
Page Parsers: reads stream data to a Page object to be parsed and operated by SiteMesh. (Not commonly used, default)
Decorator Mappers: different types of Decorator. I found that the two types of Decorator are listed below. A common mapper that specifies the configuration file name of the decorator and a printable decorator,
Can you use http: // localhost/aaa/a.html? Printable = true: The original page is provided for printing during access (so as not to include fancy pictures such as header and footer)
(But generally do not need to establish it, the default setting is enough: com/opensymphony/module/sitemesh/factory/sitemesh-default.xml ):
Example:
<Sitemesh>
<Page-parsers>
<Parser default = "true" class = "com. opensymphony. module. sitemesh. parser. DefaultPageParser"/>
<Parser content-type = "text/html" class = "com. opensymphony. module. sitemesh. parser. FastPageParser"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.