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.

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

EL Operator JSP Document Notation<br />

> gt<br />

= ge<br />

!= ne<br />

You can also use EL expressions with jsp:element to generate tags dynamically rather than<br />

hard code them. This example could be used to generate an HTML header tag with a lang<br />

attribute:<br />

<br />

${content.lang}<br />

${content.body}<br />

<br />

<strong>The</strong> name attribute identifies the generated tag’s name. <strong>The</strong> jsp:attribute tag generates the<br />

lang attribute. <strong>The</strong> body of the jsp:attribute tag identifies the value of the lang attribute. <strong>The</strong><br />

jsp:body tag generates the body of the tag. <strong>The</strong> output of this example jsp:element could be<br />

Heading in French<br />

As shown in Table 6–1, scripting elements (described in Chapter 9, “Scripting in JSP Pages”) are<br />

represented as XML elements when they appear in a JSP document. <strong>The</strong> only exception is a<br />

scriptlet expression used to specify a request-time attribute value. Instead of using ,<br />

a JSP document uses %= expr % to represent a request-time attribute value.<br />

<strong>The</strong> three scripting elements are declarations, scriptlets, and expressions.<br />

A jsp:declaration element declares a scripting language construct that is available to other<br />

scripting elements. A jsp:declaration element has no attributes and its body is the<br />

declaration itself. Its syntax is<br />

declaration goes here <br />

A jsp:scriptlet element contains a <strong>Java</strong> program fragment called a scriptlet. This element has<br />

no attributes, and its body is the program fragment that constitutes the scriptlet. Its syntax is<br />

code fragment goes here <br />

Creating a JSP Document<br />

<strong>The</strong> jsp:expression element inserts the value of a scripting language expression, converted<br />

into a string, into the data stream returned to the client. A jsp:expression element has no<br />

attributes and its body is the expression. Its syntax is<br />

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

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

Saved successfully!

Ooh no, something went wrong!