Opencms JSP Template Development-create a "complete" JSP Template

Source: Internet
Author: User

We have created a simple JSP template (see the http://blog.csdn.net/qianxuncms/archive/2007/04/09/1557085.aspx for details) through which we can create a page and edit the content of the page, this is very good for editable HTML pages.
In this article, we will see how to create a "complete" JSP template, which can be used by dynamic JSP.
The following is a simple JSP code that contains a form:

<% @ Page session = "false" %>
<HTML>
<Body>
<H1> a simple form <%
String name = request. getparameter ("name ");
If (name! = NULL )...{
%>
<H2> your name is: <% = Name %> </H2>
<% }%>
<Form name = "test" method = "get" Action = "example-jsp-simple.jsp">
<P> enter your name: <input name = "name" size = "20" value = ""> & nbsp; <input type = "Submit" value = "OK"> </P>
</Form>
</Body>
</Html>

The template can work with the page to make the same effect as the dynamic JSP page. The following uses the <CMS: Template> label to expand the template, this is a "full" version after the extension of the previous simple template. The Code is as follows:

<% @ Taglib prefix = "CMS" uri = "http://www.opencms.org/taglib/cms" %>
<CMS: Template element = "head">
<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: Template>
<CMS: Template element = "body">
<CMS: Include element = "body"/>
</CMS: Template>
<CMS: Template element = "foot">
<H2> foot of the first simple template </H2>
</Body>
</Html>
</CMS: Template>

As you can see, the only change is to add the <CMS: Template> tags, which are required. Only in this way can the JSP file obtain the element content from the template. Through this "complete" JSP template, we can conclude that all parts of the JSP template are nested and surrounded by the <CMS: Template> tag.
To use this template, add three lines of code to the JSP form page, as shown below:

<% @ Page session = "false" %>
  <% @ Taglib prefix = "CMS" uri = "http://www.opencms.org/taglib/cms" %>

<CMS: include property = "template" element = "head"/>

<H1> a simple form
<%
String name = request. getparameter ("name ");
If (name! = NULL )...{
%>
<H2> your name is: <% = Name %> </H2>
<% }%>

<Form name = "test" method = "get" Action = "example-jsp-template.jsp">
<P> enter your name: <input name = "name" size = "20" value = ""> & nbsp; <input type = "Submit" value = "OK"> </P>
</Form>

<CMS: include property = "template" element = "foot"/>

In this way, the JSP file contains the "head" and "foot" elements of the template, but how does it relate to this template? In fact, it is very simple. We only need to set the "template" attribute of the JSP file to the full path of the template file.
View the JSP file and see that it already contains the "head" and "foot" elements of the template file. So far, we have introduced the use of JSP templates and JSP files, we have a closer look at JSP templates. The next article will introduce how to create templates that contain multiple editable zones ......
Thank you for choosing opencms-the first blog in Chinese resources. You are welcome to directly communicate with the author and make progress together. MSN: qianxuncms@hotmail.com, QQ: 9165456.

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.