Use sitemesh to create a composite view-1. Hello

Source: Internet
Author: User
Tags tld
Author: Chen-neu, provided Huihoo.com released)

Use sitemesh to create a composite view-1. Hello <-now

Create a composite view using sitemesh-2. decorator

Use sitemesh to create a composite view-3. Other discussions

Sitemesh is one of the J2EE application frameworks developed by the opensymphony team. It aims to improve the maintainability and reusability of pages. Another widely-known framework of opensymphony is webwork, which is used as a web layer representation framework. They are all open-source and can be found at www.sf.net.

An example of a large project: http://opensource.thoughtworks.com/projects/sitemesh.html

    • Www.jboss.org
    • Www.theserverside.com
    • Www.opensymphony.com
    • Www.atlassian.com
Introduction:
Sitemesh uses the decorator mode to intercept requests and response with filters, and combine the page components head, content, and banner into a complete view. We usually use the include tag to continuously include various headers, stylesheet, scripts and footer in each JSP page. Now, with the help of sitemesh, we can happily delete them. For example, if you want to easily achieve the composite view mode, read this article.

Hello sitemesh:
  1. In WEB-INF/Web. XML, copy the following filter definitions:

     
                
                  sitemesh 
                 
                
                  COM. opensymphony. module. sitemesh. filter. pagefilter   
                  
                  
                    sitemesh 
                   
                  
                   /* 
                   
                  
                 
                   sitemesh-decorator 
                  
                 
                  /WEB-INF/sitemesh-decorator.tld 
                   
                 
                   sitemesh-page 
                  
                 
                  /WEB-INF/sitemesh-page.tld 
                   
                


  2. Copy the required jar and DTD files to the corresponding directory and access CVs of opensymphony.sourceforge.net to get the latest sitemesh version.
    Sitemesh. Jar WEB-INF/lib
    Sitemesh-decorator.tld WEB-INF
    Sitemesh-page.tld WEB-INF


  3. Create a WEB-INF/decorators. XML to describe the decoration pages (which can be modeled in the sitemesh example ).
    <Decorators defaultdir = "/_ decorators"> <decorator name = "Main" page = "Main. JSP "> <pattern> * </pattern> </decorator> </decorators>

  4. Create a decorators page/_ decorators/Main. jsp
     <% @ page contenttype = "text/html; charset = GBK "%> <% @ taglib uri =" sitemesh-decorator "prefix =" decorator "%>    <decorator: title default = "decorator page... "/>  
                   sitemesh example 
                 
                 
                 chen56@msn.com   


  5. Create a decoration page/index. jsp (Content Page)
    <% @ Page contenttype = "text/html; charset = GBK "%> <HTML> 

Finally, access index. jsp to generate the following page:

In addition, all pages will be changed to the same decoration mode as index. jsp by the filter of sitemesh, without the need to use the include tag.

 

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.