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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Note that jsp:root is required because otherwise books.jspx would have two root elements:<br />

and . <strong>The</strong> output generated from books.jspx will be a sequence of XML<br />

documents: one with and the other with as its root element.<br />

<strong>The</strong> output of this example will not be well-formed XML because of the two root elements, so<br />

the client might refuse to process it. However, it is still a legal JSP document.<br />

In addition to including JSP documents in JSP documents, you can also include JSP pages<br />

written in standard syntax in JSP documents, and you can include JSP documents in JSP pages<br />

written in standard syntax. <strong>The</strong> container detects the page you are including and parses it as<br />

either a standard syntax JSP page or a JSP document and then places it into the XML view for<br />

validation.<br />

Creating Static and Dynamic Content<br />

This section explains how to represent static text and dynamic content in a JSP document. You<br />

can represent static text in a JSP document using uninterpreted XML tags or the jsp:text<br />

element. <strong>The</strong> jsp:text element passes its content through to the output.<br />

If you use jsp:text, all white space is preserved. For example, consider this example using<br />

XML tags:<br />

<br />

<br />

Web Servers for Fun and Profit<br />

<br />

<br />

<strong>The</strong> output generated from this XML has all white space removed:<br />

<br />

Web Servers for Fun and Profit<br />

<br />

If you wrap the example XML with a tag, all white space is preserved. <strong>The</strong> white<br />

space characters are #x20, #x9, #xD, and #xA.<br />

You can also use jsp:text to output static data that is not well formed. <strong>The</strong> ${counter}<br />

expression in the following example would be illegal in a JSP document if it were not wrapped<br />

in a jsp:text tag.<br />

<br />

${counter}<br />

<br />

This example will output<br />

Creating a JSP Document<br />

Chapter 6 • <strong>Java</strong>Server Pages Documents 191

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

Saved successfully!

Ooh no, something went wrong!