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 />

194<br />

expression goes here <br />

Using the jsp:root Element<br />

<strong>The</strong> jsp:root element represents the root element of a JSP document. A jsp:root element is<br />

not required for JSP documents. You can specify your own root element, enabling you to use<br />

any XML document as a JSP document. <strong>The</strong> root element of the books.jspx example JSP<br />

document is books.<br />

Although the jsp:root element is not required, it is still useful in these cases:<br />

■ When you want to identify the document as a JSP document to the JSP container without<br />

having to add any configuration attributes to the deployment descriptor or name the<br />

document with a .jspx extension<br />

■ When you want to generate, from a single JSP document, more than one XML document or<br />

XML content mixed with non-XML content<br />

<strong>The</strong> version attribute is the only required attribute of the jsp:root element. It specifies the JSP<br />

specification version that the JSP document is using.<br />

<strong>The</strong> jsp:root element can also include xmlns attributes for specifying tag libraries used by the<br />

other elements in the page.<br />

<strong>The</strong> books.jspx page does not need a jsp:root element and therefore doesn’t include one.<br />

However, suppose that you want to generate two XML documents from books.jspx: one that<br />

lists books and another that lists magazines (assuming magazines are in the database). This<br />

example is similar to the one in the section “Including Directives in a JSP Document” on<br />

page 189. To do this, you can use this jsp:root element:<br />

<br />

...<br />

...<br />

<br />

Notice in this example that jsp:root defines the JSP namespace because both the books and the<br />

magazines elements use the elements defined in this namespace.<br />

Using the jsp:output Element<br />

<strong>The</strong> jsp:output element specifies the XML declaration or the document type declaration in the<br />

request output of the JSP document.<br />

<strong>The</strong> XML declaration and document type declaration that are declared by the jsp:output<br />

element are not interpreted by the JSP container. Instead, the container simply directs them to<br />

the request output.<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!