JSP.2.1 General Syntax Rules


The following general syntax rules apply to all elements in JSP pages.

JSP.2.1.1 Elements and Template Data

A JSP page has some elements and some template data . The elements are instances of some element types that are known to the JSP container; template data is everything else, i.e., anything that the JSP container does not understand.

The type of an element describes its syntax and its semantics. If the element has attributes, the type also describes the attribute names , their valid types, and their interpretation. If the element defines objects, the semantics includes what objects it defines and their types.

There are three types of elements: directive elements, scripting elements , and action elements ; the corresponding syntax is described below. Template data is uninterpreted; it is usually passed through to the client, or to some processing component.

JSP.2.1.2 Element Syntax

Most of the JSP syntax is based on XML. Elements based on the XML syntax have either a start tag (including the element name ) possibly with attributes, an optional body and a matching end tag, or they have an empty tag possibly with attributes:

 <mytag attr1="attribute value" ...>  body  </mytag> 

and

 <mytab attr1="attribute value" .../> 

JSP tags are case-sensitive, as in XML and XHTML.

Scripting elements and directives are written using a syntax that is easier to author by hand. Elements using the alternative syntax are of the form <%.....%> .

All JSP pages have an equivalent valid XML document. A future JSP specification may require JSP containers to accept JSP pages as well as their equivalent XML documents. Chapter JSP.7 describes the XML equivalent syntax for the scripting elements and directives; these XML element types are not intended to be used within a JSP page but in the equivalent XML document.

JSP.2.1.3 Start and End Tags

Elements that have distinct start and end tags (with enclosed body) must start and end in the same file. You cannot begin a tag in one file and end it in another.

This applies also to elements in the alternate syntax. For example, a scriptlet has the syntax <% scriptlet %> . Both the opening <% characters and the closing %> characters must be in the same physical file.

JSP.2.1.4 Empty Elements

Following the XML specification, an element described using an empty tag is indistinguishable from one using a start tag, an empty body, and an end tag.

JSP.2.1.5 Attribute Values

Following the XML specification, attribute values always appear quoted. Both single and double quotes can be used. The entities &apos ; and &quot ; are available to describe single and double quotes.

See also Section JSP.2.12.1, "Request-Time Attribute Values."

JSP.2.1.6 White Space

In HTML and XML, white space is usually not significant, with some exceptions. One exception is that an XML file must start with the characters <?xml , with no leading white space characters.

This specification follows the white space behavior defined for XML; that is, all white space within the body text of a document is not significant, but is preserved.

For example, since directives generate no data and apply globally to the JSP page, the following input file is translated into the corresponding result file:

For this input,

this is the default value

 <?xml version="1.0" ?> <%@ page buffer="8kb" %> The rest of the document goes here 

The result is

note the empty line

 <?xmlversion="1.0" ?> The rest of the document goes here 

As another example, for this input,

note no white between the two elements

 <% response.setContentType("...."); whatever... %><?xml version="1.0" ?> <%@ page buffer="8kb" %> The rest of the document goes here 

The result is

no leading space

note the empty line

 <?xml version="1.0" ?> The rest of the document goes here 


Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net