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.

What Is a JSP Page?<br />

134<br />

A Simple JSP Page Example<br />

<strong>The</strong> web page in Figure 5–1 is a form that allows you to select a locale and displays the date in a<br />

manner appropriate to the locale.<br />

FIGURE 5–1 Localized Date Form<br />

<strong>The</strong> source code for this example is in the tut-install/javaeetutorial5/examples/web/date/<br />

directory. <strong>The</strong> JSP page, index.jsp, appears below; it is a typical mixture of static HTML<br />

markup and JSP elements. If you have developed web pages, you are probably familiar with the<br />

HTML document structure statements (, , and so on) and the HTML statements<br />

that create a form () and a menu ().<br />

<strong>The</strong> lines in bold in the example code contain the following types of JSP constructs:<br />

■ A page directive () sets the content type returned by the page.<br />

■ Tag library directives () import custom tag libraries.<br />

■ jsp:useBean is a standard element that creates an object containing a collection of locales<br />

and initializes an identifier that points to that object.<br />

■ JSP expression language expressions (${ }) retrieve the value of object properties. <strong>The</strong><br />

values are used to set custom tag attribute values and create dynamic content.<br />

■ Custom tags (see Chapter 8, “Custom Tags in JSP Pages”) set a variable (c:set), iterate over<br />

a collection of locale names (c:forEach), and conditionally insert HTML text into the<br />

response (c:if, c:choose, c:when, c:otherwise).<br />

■ jsp:setProperty is another standard element that sets the value of an object property.<br />

■ A function (f:equals) tests the equality of an attribute and the current item of a collection.<br />

(A built-in == operator is usually used to test equality.)<br />

Here is the JSP page:<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!