background image

Creating a JSP Document

<< Deploy and Run Applications using Ant | Comply with XML syntax >>
<< Deploy and Run Applications using Ant | Comply with XML syntax >>

Creating a JSP Document

Nested inside a jsp-config element is a jsp-property-group element, which identifies the
JSP page as an XML document. See
"Identifying the JSP Document to the Container" on
page 200
for more information.
Creating a JSP Document
A JSP document is an XML document and therefore must comply with the XML standard.
Fundamentally, this means that a JSP document must be well formed, meaning that each start
tag must have a corresponding end tag and that the document must have only one root element.
In addition, JSP elements included in the JSP document must comply with the XML syntax.
Much of the standard JSP syntax is already XML-compliant, including all the standard actions.
Those elements that are not compliant are summarized in
Table 6­1
along with the equivalent
elements in XML syntax. As you can see, JSP documents are not much different from JSP pages.
If you know standard JSP syntax, you will find it easy to convert your current JSP pages to XML
syntax and to create new JSP documents.
TABLE 6­1
Standard Syntax Versus XML Syntax
Syntax Elements
Standard Syntax
XML Syntax
Comments
<%--.. --%>
<!-- .. -->
Declarations
<%! ..%>
<jsp:declaration> .. </jsp:declaration>
Directives
<%@ include .. %>
<jsp:directive.include .. />
<%@ page .. %>
<jsp:directive.page .. />
<%@ taglib .. %>
xmlns:prefix=
"tag library URL"
Expressions
<%= ..%>
<jsp:expression> .. </jsp:expression>
Scriptlets
<% ..%>
<jsp:scriptlet> .. </jsp:scriptlet>
To illustrate how simple it is to transition from standard syntax to XML syntax, let's convert a
simple JSP page to a JSP document. The standard syntax version is as follows:
<%@ taglib uri=
"http://java.sun.com/jsp/jstl/core"
prefix=
"c" %>
<%@ taglib uri=
"http://java.sun.com/jsp/jstl/functions"
prefix=
"fn" %>
<html>
<head><title>Hello</title></head>
<body bgcolor=
"white">
<img src=
"duke.waving.gif">
<h2>My name is Duke. What is yours?</h2>
Creating a JSP Document
The Java EE 5 Tutorial · September 2007
188