Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use sitemesh

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report