10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Creating a JSP Document<br />

196<br />

<strong>The</strong> JSP container will not include the XML declaration in the output when either of the<br />

following is true:<br />

■ You set the omit-xml-declaration attribute of the jsp:output element to either true or<br />

yes.<br />

■ You have a jsp:root element in your JSP document, and you do not specify<br />

omit-xml-declaration="false" in jsp:output.<br />

<strong>The</strong> JSP container will include the XML declaration in the output when either of the following is<br />

true:<br />

■ You set the omit-xml-declaration attribute of the jsp:output element to either false or<br />

no.<br />

■ You do not have a jsp:root action in your JSP document, and you do not specify the<br />

omit-xml-declaration attribute in jsp:output.<br />

<strong>The</strong> books.jspx JSP document does not include a jsp:root action nor a jsp:output.<br />

<strong>The</strong>refore, the default XML declaration is generated in the output.<br />

Generating a DocumentType Declaration<br />

A document type declaration (DTD) defines the structural rules for the XML document in<br />

which the document type declaration occurs. XML documents are not required to have a DTD<br />

associated with them. In fact, the books example does not include one.<br />

This section shows you how to use the jsp:output element to add a document type declaration<br />

to the XML output of books.jspx. It also shows you how to enter the document type<br />

declaration manually into books.jspx so that the JSP container will interpret it and validate the<br />

document against the DTD.<br />

As shown in Table 6–3, the jsp:output element has three attributes that you use to generate the<br />

document type declaration:<br />

■ doctype-root-element: Indicates the root element of the XML document.<br />

■ doctype-system: Indicates the URI reference to the DTD.<br />

■ doctype-public: A more flexible way to reference the DTD. This identifier gives more<br />

information about the DTD without giving a specific location. A public identifier resolves to<br />

the same actual document on any system even though the location of that document on each<br />

system may vary. See the XML 1.0 specification (http://www.w3.org/XML/) for more<br />

information.<br />

<strong>The</strong> rules for using the attributes are as follows:<br />

■ <strong>The</strong> doctype attributes can appear in any order.<br />

■ <strong>The</strong> doctype-root attribute must be specified if the doctype-system attribute is specified.<br />

■ <strong>The</strong> doctype-public attribute must not be specified unless doctype-system is specified.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!