How to use sitemesh
This article is to share with you about how to use sitemesh. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
First, basic concepts
1pm Sitemesh is a kind of page decoration technology:
1: it blocks page access through a filter
2: find the appropriate decoration template according to the URL of the visited page
3: extract the content of the visited page and put it in the appropriate location in the decoration template
4: finally send the decorated page to the client.
2. In sitemesh, there are two types of pages: decorative templates and ordinary pages.
1) Decoration template refers to the page used to decorate other pages.
2) ordinary pages, which generally refer to all kinds of application pages.
3. Next, let's use a simple example to illustrate the basic principle of sitemesh decorating a web page.
Second, the principle of template modification of web pages.
Through Sitemesh's registration mechanism, tell Sitemesh to use the XXX template (assuming the previous template) to decorate the visited page when accessing the path.
When the user clicks "joke about the Great Wall" (/ ShowGreatWall.do) in the left navigation bar, the "joke about the Great Wall" page on the right will be modified by the specified template.
To sum up the above process, the basic principles of Sitemesh decorating web pages can be explained by the following:
Third, the configuration and use of Sitemesh
1) add filter definition and sitemesh taglib definition to WEB-INF/web.xml
The code is as follows:
Sitemesh
Com.opensymphony.module.sitemesh.filter.PageFilter
Sitemesh
/ *
Sitemesh-decorator
/ WEB-INF/sitemesh-decorator.tld
Sitemesh-page
/ WEB-INF/sitemesh-page.tld
2) create WEB-INF/decorators.xml, which templates are configured in this file, and which URL are modified by each template, and which URL can also be configured without template control. An example of decorators.xml is as follows:
The code is as follows:
/ Login*
/ *
/ showinfo.jsp*
/ myModule/GreatWallDetailAction.do*
3) Let's look at an example of a modified template
The code is as follows:
Hello World
4) Let's look at an example of a modified page:
The code is as follows:
Hello World
Decorated page goes here.