background image

Declaring Tag Libraries

<< Comply with XML syntax | Including Directives in a JSP Document >>
<< Comply with XML syntax | Including Directives in a JSP Document >>

Declaring Tag Libraries

The > symbol in the EL expression has been replaced with gt.
The include directive has been changed to the XML-compliant jsp:directive.include
tag.
With only these few small changes, when you save the file with a .jspx extension, this page is a
JSP document.
Using the example described in
"The Example JSP Document" on page 185
, the rest of this
chapter gives you more details on how to transition from standard syntax to XML syntax. It
explains how to use XML namespaces to declare tag libraries, include directives, and create
static and dynamic content in your JSP documents. It also describes jsp:root and jsp:output,
two elements that are used exclusively in JSP documents.
Declaring Tag Libraries
This section explains how to use XML namespaces to declare tag libraries.
In standard syntax, the taglib directive declares tag libraries used in a JSP page. Here is an
example of a taglib directive:
<%@ taglib uri=
"http://java.sun.com/jsp/jstl/core" prefix="c" %>
This syntax is not allowed in JSP documents. To declare a tag library in a JSP document, you use
the xmlns attribute, which is used to declare namespaces according to the XML standard:
...
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
...
The value that identifies the location of the tag library can take three forms:
A plain URI that is a unique identifier for the tag library. The container tries to match it
against any <taglib-uri> elements in the application's web.xml file or the <uri> element of
tag library descriptors (TLDs) in JAR files in /WEB-INF/lib/ or TLDs under WEB-INF.
A URN of the form urn:jsptld:path.
A URN of the form urn:jsptagdir:path.
The URN of the form urn:jsptld:path points to one tag library packaged with the application:
xmlns:u=
"urn:jsptld:/WEB-INF/tlds/my.tld"
The URN of the form urn:jsptagdir:path must start with /WEB-INF/tags/ and identifies tag
extensions (implemented as tag files) installed in the /WEB-INF/tags/ directory or a
subdirectory of it:
xmlns:u=
"urn:jsptagdir:/WEB-INF/tags/mytaglibs/"
Creating a JSP Document
The Java EE 5 Tutorial · September 2007
190