Sitemesh 3 Use and configuration

Source: Internet
Author: User

1:sitemesh Introduction

Sitemesh is a Web page layout and decoration framework, which can be used to separate the content of the page and the structure of the page to achieve the purpose of page structure sharing.

Sitemesh is a servlet-based filter, which is a filtered stream. It is done by intercepting the response and decorating it before delivery to the customer.

It involves two nouns: a decorative page (Decorator page) and a "decorated page", which sitemesh the content page by decorating it, eventually getting the page layout and appearance consistent, and returning it to the customer.

Sitemesh Baidu Encyclopedia

  

  

2:sitemesh 3 Installation:

Add the following dependencies in the Pom.xml file:

<!--############## Sitemash ############## -<Dependency>    <groupId>Org.sitemesh</groupId>    <Artifactid>Sitemesh</Artifactid>    <version>3.0.0</version></Dependency>

or download the Sitemesh package and manually refer to the project:

GitHub Address: Https://github.com/sitemesh/sitemesh3

3: Add Sitemesh 3 filter:

Add the following filter configuration to the project's Web. XML:

<Filter>  <Filter-name>Sitemesh</Filter-name>  <Filter-class>Com.opensymphony.sitemesh.webapp.SiteMeshFilter</Filter-class></Filter> <filter-mapping>  <Filter-name>Sitemesh</Filter-name>  <Url-pattern>/*</Url-pattern></filter-mapping>

4: Prepare "Decorate page" and "Decorate page":

Decorative pages are used to decorate other ordinary pages, such as header.html,footer.html placed in the decoration page, you can also be in the decorating page to introduce some of the pages need to js,css or pictures.

A simple decorating page looks like this:

<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><%@ taglib Prefix="C"URI="Http://java.sun.com/jsp/jstl/core"%><%@ taglib Prefix="Sitemesh"URI="Http://www.opensymphony.com/sitemesh/decorator" %><!DOCTYPE HTML><HTML><Head>    <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />    <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge" />    <Metaname= "Renderer"content= "WebKit" />    <Metaname= "keywords"content= "financial abundance, internet finance, peer-to, network investment and financing platform, Internet banking, personal finance, investment and financial management, peer-to-finance, 100% interest and interest protection, financing projects, seasonal abundance, monthly win, weekly earnings, caiduoduo.com"/>    <Metaname= "description"content= "caiduoduo.com" provides professional, thoughtful and robust Internet financial services for Internet banking users and SMEs. The funds are paid by the third party (ePRO payment) in full escrow; Project 100% Principal and interest protection, investment flexibility "/>    <Metaname= "Author"content= "Beijing Rich Investment Management Co., Ltd." />    <Metaname= "Viewport"content= "User-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=1024" />    <Linkrel= "shortcut icon"href= "Http://oss.bomeix.com/H5Template/common/img/favicon.ico">    <title>        <Sitemesh:title/>    </title>    <Sitemesh:head/></Head><Body>    <Header>Header</Header>    <Sitemesh:usepageID= "Thepage" />    <%--First- level menu selection--%>    <Sitemesh:body/>    <Footer>Footer</Footer></Body></HTML>

And a simple decorated page is as follows:

<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><!DOCTYPE HTML><HTML>  <Head>  <Metaname= "Viewport"content= "Width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, User-scalable=no"/>  <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />  <Metaname= "keywords"content=""><Metaname= "description"content=""><title>This is a test</title></Head><Body>Hello world! This is a test!</Body></HTML>

5: Prepare the Sitemesh 3 configuration file:

Create a new Decorators.xml file, placed in the/web-inf directory, which defines which requests correspond to which decorating pages, or which requests are not decorated:

<?XML version= "1.0" encoding= "UTF-8"?><DecoratorsDefaultDir= "/web-inf/views/decorators/">    <excludes>        <pattern>/static/*</pattern>    </excludes>    <!--Default Template -    <Decoratorname= "Default"page= "decorator.jsp">        <pattern>/*</pattern>    </Decorator></Decorators>

As shown in the above code, all requests use decorator.jsp as the decorating page. and does not intercept requests under the/static/folder.

6: Effect:

Sitemesh 3 Use and configuration

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.