Built a composite view using Sitemesh - 2. Decorator Decorator
Establish a composite view using Sitemesh - 1.Hello
Create a composite view using Sitemesh - 2. Decorator <- Now
Establish a composite view using Sitemesh - 3. Other discussion
Decorator Decorator Concept Establish a reuse web application, a general method is to create a hierarchical system, such as one of the following ordinary web applications:
Front end, Front-end: JSP and servlets, or Jakarta's Velocity Control Framework Controller: (struts / webwork) Business logic Business: Main business logic persistence frame: Hibernate / JDO is badly the front-end page logic is difficult Using, when you use an endless include in each page, you will have a problem-repeated code, and each page must be replicated with a page structure with COPY. And when you need a creative changing page structure, the disaster falls in love with you. Sitemesh intercepts Request and Response via Filter and adds a certain decoration to the original page (possibly header, footer ...), then return the result to the client, and the original page is decorated does not know the decoration of Sitemesh, this Differential purposes are also achieved. It is said that the newly introduced portlet specification will help our standards to achieve more Cool ideas than these more Cool ideas, but poor, I still don't understand it is a Shou Dongdong, interested person can study JetSpeed, or JSR (Java) Specification request) 168, but I want Sitemesh so simple, we may wish to use it first. Let's see how to configure the environment In addition to copymesh.jar in Web-INF / LIB, Copy to Web-INF Sitemesh-Decorator.TLD, SiteMesh-Page.TLD file, there are 2 files to establish To web-inf /:
Sitemesh.xml (optional) Decorators.xml sitemesh.xml can set 2 information: Page Parsers: Responsible for reading Stream into a Page object to resolve and operate with Sitemesh. (Not often used, default) Decorator mappers: Different decorative types, I found that two more useful are listed below. A universal mapper, can specify the configuration file name of the decorator, another printable decorator, can allow you to use http: //localhost/aa/a.html? Printable = true to give the original page for printing (lest the header, footer, etc. can also catch the fancy pictures) (but generally do not build it, the default setting is enough: com / opensymphony / module / sitemesh / factory / sitemesh-default.xml): example:
DefaultDir: Contentd Directory containing the decorator page Page: page file name Name: alias role: role, for secure WebApp: You can specify this file to save the directory patterns: Match the path, you can use *, those accessed, need to be decorated . The most important thing is to write the decorator itself (that is, those to reuse the page, and the structure page). In fact, important work is to make the decorator page itself (that is, a page containing structure and rules), then describes them into Decorators.xml. Let's take a look at the simple use: In fact, the most commonly used simple use is our Hello example, in the face of such a large number of technologies, I want to achieve the function point, there is no need to study too deep (Unless you have a deeper demand). <% @ page contenttype = "text / html; charset = GBK"%>
<% @ Taglib Uri = "SiteMesh-Decorator" prefix = "decorator"%>
Decorator Tagspage Tags is used to create an decorator page. It is used to access the decorator from the original content page.