Opencms JSP Template Development-create a simple JSP Template

Source: Internet
Author: User

The JSP template in opencms is a common JSP page that uses tags to contain content at specific locations. In this example, we will develop a simple JSP template, this template only adds some tags around the content (such as <HTML> and <body>.
This JSP template is located under the templates sub-folder under the module, such as/system/modules/org. opencms. Test/templates,

The template file is as follows:

<% @ Taglib prefix = "CMS" uri = "http://www.opencms.org/taglib/cms" %>
<HTML>
<Head>
<Title> <CMS: property name = "title"/> </title>
<Meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = <CMS: property name =" content-encoding "default =" UTF-8 "/>"/>
<LINK rel = "stylesheet" type = "text/CSS" href = "<CMS: link> ../resources/mystyle.css </CMS: link>"/>
</Head>
<Body>
<H2> head of the first simple template </H2>
<CMS: Include element = "body"/>
<H2> foot of the first simple template </H2>
</Body>
</Html>

Before using the opencms label, you must declare the label as follows:<% @ Taglib prefix = "CMS" uri = "http://www.opencms.org/taglib/cms" %>, for a detailed description of the label, I have a few articles have been described in opencms JSP label details -- CMS: label Label. opencms JSP labels -- CMS: link label,Opencms JSP tag details -- CMS: Property tag, opencms JSP tag details -- CMS: user tag CMS: IMG Tag usage instructions)

Note: The JSP template is stored in the "templates" sub-folder under the module. Only in this way will the template appear in the template selection list when the page is created, as shown in, create a page using this template and select the type page:

 

Enter the file name, and then select "A simple JSP template". The Template Name displayed here is the content of the title attribute of the JSP template:

After the page is created, select the Edit page, for example:

In this example, the page title is read from the "title" attribute of the opencms page and placed in the <title> tag of HTML. The page encoding method is similar to the definition method.
The style sheet must be placed in the <CMS: link> label. In the JSP template, the pattern table path should be a relative path relative to the template path, create a resource sub-folder under the module to store resources such as style sheets and images related to the template. Of course, this is not necessary, but it is indeed a good habit.
Note: You can use CSS style sheets in the editor by setting the "template" attribute of the template. This value must be a full path of the style sheet, when editing the page, the editor calls this CSS style, which is consistent with the style seen during page browsing.
The most important line in this example is the "<CMS: Include element =" body ">" tag, which contains an editable page element.

Edit the page, that is, edit the "body" element in the page. Because the JSP template specifies CSS, the entered content is displayed in the CSS style:

Finally, browse this file, for example:

In this way, the creation process of a simple JSP template is completed, and the introduction of JSP Template Development will continue later ......

 

Related Article

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.