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.

Creating a JSP Document<br />

192<br />

123<br />

<strong>The</strong> jsp:text tag must not contain any other elements. <strong>The</strong>refore, if you need to nest a tag<br />

inside jsp:text, you must wrap the tag inside CDATA.<br />

You also need to use CDATA if you need to output some elements that are not well-formed. <strong>The</strong><br />

following example requires CDATA wrappers around the blockquote start and end tags because<br />

the blockquote element is not well formed. This is because the blockquote element overlaps<br />

with other elements in the example.<br />

<br />

]]><br />

<br />

...<br />

<br />

]]><br />

<br />

Just like JSP pages, JSP documents can generate dynamic content using expressions language<br />

(EL) expressions, scripting elements, standard actions, and custom tags. <strong>The</strong> books.jspx<br />

document uses EL expressions and custom tags to generate the XML book data.<br />

As shown in this snippet from books.jspx, the c:forEach JSTL tag iterates through the list of<br />

books and generates the XML data stream. <strong>The</strong> EL expressions access the <strong>Java</strong>Beans<br />

component, which in turn retrieves the data from the database:<br />

<br />

<br />

${book.surname}<br />

${book.firstName}<br />

${book.title}<br />

${book.price}<br />

${book.year}<br />

${book.description}<br />

${book.inventory}<br />

<br />

<br />

When using the expression language in your JSP documents, you must substitute alternative<br />

notation for some of the operators so that they will not be interpreted as XML markup.<br />

Table 6–2 enumerates the more common operators and their alternative syntax in JSP<br />

documents.<br />

TABLE 6–2 EL Operators and JSP Document-Compliant Alternative Notation<br />

EL Operator JSP Document Notation<br />

< lt<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!