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.

You can include the xmlns attribute in any element in your JSP document, just as you can in an<br />

XML document. This capability has many advantages:<br />

■ It follows the XML standard, making it easier to use any XML document as a JSP document.<br />

■ It allows you to scope prefixes to an element and override them.<br />

■ It allows you to use xmlns to declare other namespaces and not just tag libraries.<br />

<strong>The</strong> books.jspx page declares the tag libraries it uses with the xmlns attributes in the root<br />

element, books:<br />

<br />

In this way, all elements within the books element have access to these tag libraries.<br />

As an alternative, you can scope the namespaces:<br />

<br />

...<br />

<br />

<br />

<br />

<br />

...<br />

<br />

<br />

In this way, the tag library referenced by the jsp prefix is available only to the jsp:useBean<br />

element and its subelements. Similarly, the tag library referenced by the c prefix is only available<br />

to the c:forEach element.<br />

Scoping the namespaces also allows you to override the prefix. For example, in another part of<br />

the page, you could bind the c prefix to a different namespace or tag library. In contrast, the jsp<br />

prefix must always be bound to http://java.sun.com/JSP/Page, the JSP namespace.<br />

Including Directives in a JSP Document<br />

Creating a JSP Document<br />

Directives are elements that relay messages to the JSP container and affect how it compiles the<br />

JSP page. <strong>The</strong> directives themselves do not appear in the XML output.<br />

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

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

Saved successfully!

Ooh no, something went wrong!