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

Source: Internet
Author: User

Use sitemesh to create a composite view-1. Hello

Create a composite view using sitemesh-2. decorator

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

The previous article is enough to use sitemesh to improve your application, but I found that there are other things that may be helpful to you.

Printable interface Decoration
As mentioned above, there is a printable decoration device that allows you to use http: // localhost/AAA/a.html? When the printable = true method is used for access, other decorator will be applied (specified by yourself) and the original page will be provided for printing (so as not to include fancy pictures such as header and footer ).

Let's take a look at how to implement it:

1. First set in Web-info/sitemesh. xml:
<Mapper class = "com. opensymphony. Module. sitemesh. Mapper. printabledecoratormapper">
<Param name = "decorator" value = "printable"/>
<Param name = "parameter. Name" value = "printable"/>
<Param name = "parameter. Value" value = "true"/>
</Mapper>
In this way, you can pass? Printable = true, instead of the original one.

2. Define the corresponding printable decorators in Web-info/decorators. xml.
<Decorator name = "printable" page = "printable. jsp"/>

3. Finally, write the printable decorator/decorators/printable. jsp.

<% @ Taglib uri = "sitemesh-decorator" prefix = "decorator" %>
<HTML>
<Head>
<Title> <decorator: Title/> </title>
<Decorator: Head/>
</Head>
<Body>

<H1> <decorator: Title/> <P align = "right"> <I> (printable version) </I> </P>

<Decorator: body/>

</Body>
</Html>

So that an original page can pass through? Printable = true switch to switch between different decorator pages.

 

Chinese questions
Because the default character set used inside sitemesh is the iso-8859-1, using it directly produces garbled characters, which can be corrected:

  • Method 1: You can find it in the configuration file of your application server. Is there any encoding orCharset project, and set it to GBK or gb2312.
  • Method 2: This is what we have been using.
    1. Set <% @ page contenttype = "text/html; charset = GBK" %> on each JSP page to tell the server the character set you require.
    2. Define in the head of each JSP page: <meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = GBK"> to tell the browser what character set you are using.
Conclusion: The most common way to use sitemesh is:

1. Configure the environment,

2. Describe the package you will create in Web-info/decroators. xml.

3. Develop the package described in decroators. xml. It is best to store it in the/_ decorators directory.

4. OK. Let's take a look at the hard work.

Resource:

  • Download the ant build example I provided
    I passed the test in j2sdk-1_4_0, tomcat4.0.3 and tomcat5. Run/build. bat first to generate the/Dist/Web. War file and then implement it to your server.
  • Project set of the opensymphony team:
    Http://sourceforge.net/projects/opensymphony
  • Wiki: http://wiki.opensymphony.com/
  • Download the latest version of CVS from the CVs of SF.

About Author:

Chen Peng, Xi'an Neusoft company. As an avid programmer, I hope to grow and improve every day and share my happiness and knowledge with you.
Contact him in the following ways: email chen56@msn.com

 

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.