JSP
JSP
Specification
Version2.0
TRADEMARKS
No right, title, or interest in or to any trademarks, service marks, or trade
names of Sun or Sun’s licensors is granted hereunder. Sun, Sun Microsystems, the
Sun logo, Java, the Java Coffee Cup logo, JSP, and JavaServer Pages are
trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and
other countries.
DISCLAIMER OF WARRANTIES
THE SPECIFICATION IS PROVIDED “AS IS”. SUN MAKES NO
REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO, WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-
INFRINGEMENT, THAT THE CONTENTS OF THE SPECIFICATION ARE
SUITABLE FOR ANY PURPOSE OR THAT ANY PRACTICE OR
IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY
THIRD PARTY PATENTS, COPYRIGHTS, TRADE SECRETS OR OTHER
RIGHTS. This document does not represent any commitment to release or
implement any portion of the Specification in any product.
THE SPECIFICATION COULD INCLUDE TECHNICAL
INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE
PERIODICALLY ADDED TO THE INFORMATION THEREIN; THESE
CHANGES WILL BE INCORPORATED INTO NEW VERSIONS OF THE
SPECIFICATION, IF ANY. SUN MAY MAKE IMPROVEMENTS AND/OR
CHANGES TO THE PRODUCT(S) AND/OR THE PROGRAM(S)
DESCRIBED IN THE SPECIFICATION AT ANY TIME. Any use of such
changes in the Specification will be governed by the then-current license for the
applicable version of the Specification.
LIMITATION OF LIABILITY
TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL
SUN OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES, INCLUDING
WITHOUT LIMITATION, LOST REVENUE, PROFITS OR DATA, OR FOR
SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
OF LIABILITY, ARISING OUT OF OR RELATED TO ANY FURNISHING,
PRACTICING, MODIFYING OR ANY USE OF THE SPECIFICATION, EVEN
IF SUN AND/OR ITS LICENSORS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
You will indemnify, hold harmless, and defend Sun and its licensors from any
claims arising or resulting from: (i) your use of the Specification; (ii) the use or
distribution of your Java application, applet and/or clean room implementation;
and/or (iii) any claims that later versions or releases of any Specification furnished
to you are incompatible with the Specification provided to you under this license.
REPORT
You may wish to report any ambiguities, inconsistencies or inaccuracies you
may find in connection with your use of the Specification (“Feedback”). To the
extent that you provide Sun with any Feedback, you hereby: (i) agree that such
Feedback is provided on a non-proprietary and non-confidential basis, and (ii)
grant Sun a perpetual, non-exclusive, worldwide, fully paid-up, irrevocable
license, with the right to sublicense through multiple levels of sublicensees, to
incorporate, disclose, and use without limitation the Feedback for any purpose
related to the Specification and future versions, implementations, and test suites
thereof.
(LFI#136181/Form ID#011801)
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix
The JavaServer Pages™ Technology . . . . . . . . . . . . . . . . . . . . . xxix
Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi
Users of JavaServer Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiii
Part I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
JSP.1 Core Syntax and Semantics . . . . . . . . . . . . . . . . . . . . . . . 1-3
JSP.1.1 What Is a JSP Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
JSP.1.1.1 Web Containers and Web Components . . . . . . 1-3
JSP.1.1.2 Generating HTML . . . . . . . . . . . . . . . . . . . . . . 1-4
JSP.1.1.3 Generating XML . . . . . . . . . . . . . . . . . . . . . . . 1-4
JSP.1.1.4 Translation and Execution Phases . . . . . . . . . . 1-4
JSP.1.1.5 Validating JSP pages . . . . . . . . . . . . . . . . . . . . 1-5
JSP.1.1.6 Events in JSP Pages . . . . . . . . . . . . . . . . . . . . . 1-6
JSP.1.1.7 JSP Configuration Information . . . . . . . . . . . . 1-6
JSP.1.1.8 Naming Conventions for JSP Files . . . . . . . . . 1-6
JSP.1.1.9 Compiling JSP Pages . . . . . . . . . . . . . . . . . . . . 1-7
JSP.1.1.10 Debugging JSP Pages . . . . . . . . . . . . . . . . . . . 1-8
JSP.1.2 Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
JSP.1.2.1 Relative URL Specifications . . . . . . . . . . . . . . 1-9
JSP.1.3 Syntactic Elements of a JSP Page . . . . . . . . . . . . . . . . 1-10
JSP.1.3.1 Elements and Template Data . . . . . . . . . . . . . 1-10
JSP.1.3.2 Element Syntax . . . . . . . . . . . . . . . . . . . . . . . 1-10
JSP.1.3.3 Start and End Tags . . . . . . . . . . . . . . . . . . . . . 1-11
JSP.1.3.4 Empty Elements . . . . . . . . . . . . . . . . . . . . . . . 1-12
JSP.1.3.5 Attribute Values . . . . . . . . . . . . . . . . . . . . . . . 1-12
JSP.1.3.6 The jsp:attribute, jsp:body and jsp:element Elements
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12
JSP.1.3.7 Valid Names for Actions and Attributes . . . . 1-14
JSP.1.3.8 White Space . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14
JSP.1.3.9 JSP Documents . . . . . . . . . . . . . . . . . . . . . . . 1-15
76
E.10.10 Typographical Fixes and Version Numbers . . 3-76
E.10.11 Added EBNF Grammar for JSP Standard Syntax 3-
76
E.10.12 Added Users of JavaServer Pages Section . . . 3-77
E.10.13 Added Placeholders for Expression Language and
Custom Actions Using JSP . . . . . . . . . . . . . . . 3-77
E.10.14 Added Requirement for Debugging Support . 3-77
JSP.E.11 Changes Between PFD 2 and Final Draft . . . . . . . . . . 3-77
E.11.15 Added jsp:id mechanism . . . . . . . . . . . . . . . . . 3-77
E.11.16 Other Small Changes . . . . . . . . . . . . . . . . . . . 3-77
E.11.17 Clarification of role of id . . . . . . . . . . . . . . . . 3-78
E.11.18 Clarifications on Multiple Requests and Threading
3-78
E.11.19 Clarifications on JSP Documents . . . . . . . . . . 3-78
E.11.20 Clarifications on Well Known Tag Libraries . 3-78
E.11.21 Clarified Impact of Blocks . . . . . . . . . . . . . . . 3-79
E.11.22 Other Small Clarifications . . . . . . . . . . . . . . . 3-79
JSP.E.12 Changes Between 1.2 PFD 1b and PFD 2 . . . . . . . . . 3-80
E.12.23 Added elements to Tag Library Descriptor . . 3-80
E.12.24 Changed the way version information is encoded into
TLD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-80
E.12.25 Assigning String literals to Object attributes . 3-80
E.12.26 Clarification on valid names for prefix, action and at-
tributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-81
E.12.27 Clarification of details of empty actions . . . . . 3-81
E.12.28 Corrections related to XML syntax . . . . . . . . . 3-81
E.12.29 Other changes . . . . . . . . . . . . . . . . . . . . . . . . . 3-81
JSP.E.13 Changes Between 1.2 PFD and 1.2 PFD 1b . . . . . . . . 3-82
JSP.E.14 Changes Between 1.2 PD1 and 1.2 PFD . . . . . . . . . . . 3-82
E.14.30 Deletions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-83
E.14.31 Additions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-83
E.14.32 Clarifications . . . . . . . . . . . . . . . . . . . . . . . . . . 3-83
E.14.33 Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-84
JSP.E.15 Changes Between 1.1 and 1.2 PD1 . . . . . . . . . . . . . . . 3-84
E.15.34 Organizational Changes . . . . . . . . . . . . . . . . . 3-84
E.15.35 New Document . . . . . . . . . . . . . . . . . . . . . . . . 3-85
E.15.36 Additions to API . . . . . . . . . . . . . . . . . . . . . . . 3-85
JSP 2.0 extends the JavaServer Pages 1.2 Specification (JSP 1.2) in the follow-
ing ways:
• The JSP 2.0 specification requires the Java™ 2 Platform, Standard Edition ver-
sion 1.3 or later for standalone containers, and version 1.4 for containers that
are part of a Java 2 Enterprise Edition 1.4 environment. All JSP containers
must be able to run in a J2SE 1.4 environment.
• The JSP 2.0 specification uses the Servlet 2.4 specification for its web seman-
tics.
• A simple Expression Language (EL) has been added. The EL can be used to
easily access data from the JSP pages. The EL simplifies writing script-less
JSP pages that do not use Java scriptlets or Java expressions and thus have a
more controlled interaction with the rest of the Web Application.
• New syntax elements for defining custom actions using the JSP technology
directly have been added. These elements are delivered into .tag and .tagx files
which can be authored by developers and page authors alike to provide encap-
sulation and reusability of common actions.
• The XML syntax has been clarified and improved substantially. New standard
extensions have been added for JSP pages (.jspx) and for tag files (.tagx). We
expect that the new mechanisms will compel authors to use the XML syntax
to generate XML documents in JSP 2.0.
• An API for invoking the EL has been added. This API will likely be used in
the implementation of the EL in JSP 2.0 and JSTL but we expect it to also be
used in other technologies like JavaServer™ Faces.
• A new Simple Invocation Protocol has been added. This API exploits what we
expect to be the prevalent use of script-less pages. The simple invocation pro-
tocol avoids the complex “inverted closure” mechanism of the classic invoca-
tion protocol introduced in JSP 1.1 and is used for implementing tag files.
Where possible, JSP 2.0 attempts to be fully backwards compatible with JSP
1.2. In some cases, there are ambiguities in the JSP 1.2 specification that have
been clarified in JSP 2.0. Because some JSP 1.2 containers behave differently,
some applications that rely on container-specific behavior may need to be adjusted
to work correctly in a JSP 2.0 environment.
1. Tag Library Validators that are not namespace aware and that rely solely on
the prefix parameter may not correctly validate some JSP 2.0 pages. This is be-
cause the XML view may contain tag library declarations in elements other
than jsp:root, and may contain the same tag library declaration more than once,
using different prefixes. The uri parameter should always be used by tag li-
brary validators instead. Existing JSP pages with existing tag libraries will not
have any problems.
2. Users may observe differences in I18N behavior on some containers due pri-
marily to ambiguity in the JSP 1.2 specification. Where possible, steps were
taken to minimize the impact on backwards compatibility and overall, JSP’s
I18N abilities have been greatly improved.
In JSP specification versions previous to JSP 2.0, JSP pages in XML syntax
("JSP documents") and those in standard syntax determined their page encod-
ing in the same fashion, by examining the pageEncoding or contentType
attributes of their page directive, defaulting to ISO-8859-1 if neither was
present.
As a result of this change, JSP documents that rely on their page encoding to
be determined from their pageEncoding attribute will no longer be decoded
correctly. These JSP documents must be changed to include an appropriate
XML encoding declaration.
3. The type coercion rules in Table JSP.1-11 have been reconciled with the EL
coercion rules. There are some exceptional conditions that will no longer re-
sult in an exception in JSP 2.0. In particular, when passing an empty String("")
to an attribute of a numeric type, a translation error or a NumberFormatExcep-
tion used to occur, whereas in JSP 2.0 a 0 will be passed in instead. See the
new Table JSP.1-11 for details. In general, this is not expected to cause any
problems because these would have been exceptional conditions in JSP 1.2 and
the specification allowed for these exceptions to occur at either translation time
or request time.
The JSP container uses the version of web.xml to determine whether you are
running a JSP 1.2 application or a JSP 2.0 application. Various features may
behave differently depending on the version of web.xml. The following is a list of
things JSP developers should be aware of when upgrading their web.xml from
version Servlet 2.3 to version Servlet 2.4:
Licensing of Specification
Details on the conditions under which this document is distributed are described
in the license agreement on page iii.
covers material pertaining to a wide audience, including Page Authors, Tag Library
Developers, Deployers, Container Vendors, and Tool Vendors.
This document is not intended to be a user’s guide. We expect other
documents will be created that will cater to different readerships.
Related Documents
Implementors of JSP containers and authors of JSP pages may find the follow-
ing documents worth
: consulting for additional information
Historical Note
The following individuals were pioneers who did ground-breaking work on the
Java platform areas related to this specification. James Gosling’s work on a Web
Server in Java in 1994/1995 became the foundation for servlets. A larger project
emerged in 1996 with Pavani Diwanji as lead engineer and with many other key
members listed below. From this project came Sun’s Java Web Server product.
Things started to move quickly in 1999. The servlet expert group, with James
Davidson as lead, delivered the Servlet 2.1 specification in January and the Servlet
2.2 specification in December, while the JSP group, with Larry Cable and
Eduardo Pelegri-Llopart as leads, delivered JSP 1.0 in June and JSP 1.1 in
December.
The year 2000 saw a lot of activity, with many implementations of containers,
tools, books, and training that target JSP 1.1, Servlet 2.2, and the Java 2 Platform,
Enterprise Edition. Tag libraries were an area of intense development, as were
varying approaches to organizing all these features together. The adoption of JSP
technology has continued in the year 2001, with many talks at the “Web, Services
and beyond” track at JavaOne being dedicated to the technology.
The JSP 1.2 specification went final in 2001. JSP 1.2 provided a number of
fine-tunings of the spec. It also added the ability for validating JSP pages through
the XML views of a JSP page. JSP 1.2 also introduced a normative XML syntax
for JSP pages, but its adoption was handicaped by several specification
shortcomings.
JSP 2.0 is a major revision of the JSP language. Key new features include a
simple Expression Language, tag files, substantial simplifications for writing tag
handlers in Java and the notion of JSP fragments. JSP 2.0 also includes a revision
of the XML syntax that addresses most of the problems in JSP 1.2.
Tracking the industry in a printed document is at best difficult; the industry
pages at the web site at http://java.sun.com/products/jsp do a better job.
Acknowledgments
perspective fresh in our minds, and Umit Yalcinalp for her conversion of the TLD
and deployment descriptors into XML Schema.
We want to thank all the authors of books on JSP technology, and the creators
of the web sites that are tracking and facilitating the creation of the JSP
community.
The editors want to give special thanks to many individuals within the Java 2
Enterprise Edition team, and especially to Jean-Francois Arcand, Jennifer Ball,
Stephanie Bodoff, Pierre Delisle, Jim Driscoll, Cheng Fang, Robert Field, Justyna
Horwat, Dianne Jiao, Norbert Lindenberg, Ryan Lubke, Jan Luehe, Craig
McClanahan, Bill Shannon, Prasad Subramanian, Norman Walsh, Yutaka
Yoshida, Kathleen Zelony, and to Ian Evans for his editorial work.
Lastly, but most importantly, we thank the software developers, web authors
and members of the general public who have read this specification, used the
reference implementation, and shared their experience. You are the reason the
JavaServer Pages technology exists!
This is the final draft of the JSP 2.0 specification, developed by the expert
group JSR-152 under the Java Community Process (more details at http://jcp.org/
jsr/detail/152.jsp).
The original Java Specification Request (JSR-152) listed the version number
of the specification as 1.3. The scope and content of the specification effort has
not changed, but the expert group realized that the new features would have a deep
impact on the development model of JSP applications and decided that 2.0 would
more appropriately reflect that impact.
The JCP is designed to be a very flexible process so each expert group can
address the requirements of the specific communities it serves. The reference imple-
mentation for JSP 2.0 and Servlet 2.4 uses code that is being developed as an open
source project under an agreement with the Apache Software Foundation.
This specification includes chapters that are derived directly from the Javadoc
comments in the API classes, but, were there to be any discrepancies, this
specification has precedence over the Javadoc comments.
The JCP process provides a mechanism for updating the specification through
a maintenance process using erratas. If available, the erratas will have precedence
over this specification.
General Concepts
JSP technology provides the means for textual specification of the creation of a
dynamic response to a request. The technology builds on the following concepts:
• Template Data
A substantial portion of most dynamic content is fixed or template content.
Text or XML fragments are typical template data. JSP technology supports
natural manipulation of template data.
• Encapsulation of Functionality
JSP technology provides two related mechanisms for the encapsulation of
functionality: JavaBeans™ component architecture, and tag libraries deliver-
• Separation of Roles
JSP supports the separation of developer and author roles. Developers write
components that interact with server-side objects. Authors put static data and
dynamic content together to create presentations suited for their intended
audience.
Each group may do their job without knowing the job of the other. Each role
emphasizes different abilities and, although these abilities may be present in
the same individual, they most commonly will not be. Separation allows a nat-
ural division of labor.
A subset of the developer community may be engaged in developing reusable
components intended to be used by authors.
Basic Concepts
This section introduces basic concepts that will be defined formally later in the
specification.
• Standard directives
• Standard actions
• Scripting elements
• Tag Extension mechanism
• Template content
Web Applications
The concept of a web application is inherited from the servlet specification. A
web application can be composed of:
The JavaServer Pages specification inherits from the servlet specification the
concepts of web applications, ServletContexts, sessions, and requests and
responses. See the Java Servlet 2.4 specification for more details.
There are six classes of users that interact with JavaServer Pages technology.
This section describes each class of user, enumerates the technologies each must be
familiar with, and identifies which sections of this specification are most relevant to
each user class. The intent is to ensure that JavaServer Pages remains a practical and
easy-to-use technology for each class of user, even as the language continues to
grow.
Page Authors
Page Authors are application component providers that use JavaServer Pages to
develop the presentation component of a web application. It is expected that they
will not make use of the scripting capabilities of JavaServer Pages, but rather limit
their use to standard and custom actions. Therefore, it is assumed that they know the
target language, such as HTML or XML, and basic XML concepts, but they need
not know Java at all.
The following sections are most relevant to this class of user:
• Chapter JSP.1, “Core Syntax and Semantics”, except for Section JSP.1.12,
“Scripting Elements” and Section JSP.1.14, “Tag Attribute Interpretation Se-
mantics”, which both talk about scripting.
• Chapter JSP.2, “Expression Language”
• Chapter JSP.3, “JSP Configuration”
• Chapter JSP.4, “Internationalization Issues”
• Chapter JSP.5, “Standard Actions”
• Chapter JSP.6, “JSP Documents”, except for sections that discuss declara-
tions, scriptlets, expressions, and request-time attributes.
• Section JSP.7.1.1, “Goals” and Section JSP.7.1.2, “Overview” of
Chapter JSP.7, “Tag Extensions”.
• Chapter JSP.8, “Tag Files”.
• Appendices JSP.A, JSP.E, and JSP.F.
Deployers
A deployer is an expert in a specific operational environment who is responsible
for configuring a web application for, and deploying the web application to, that
environment. The deployer does not need to understand the target language or Java,
but must have an understanding of XML or use tools that provide the ability to read
deployment descriptors.
The following sections are most relevant to this class of user:
• Section JSP.1.1, “What Is a JSP Page” and Section JSP.1.2, “Web Applica-
tions” of Chapter JSP.1, “Core Syntax and Semantics”
• Chapter JSP.3, “JSP Configuration”
• Chapter JSP.4, “Internationalization Issues”
• Chapter JSP.11, “JSP Container”
• All Appendices.
The next chapters form the core of the JSP specification. These chapters pro-
vide information for Page authors, Tag Library developers, deployers and Container
and Tool vendors.
The chapter of this part are
This chapter describes the core syntax and semantics for the JavaServer Pages
2.0 specification (JSP 2.0).
A JSP page is a textual document that describes how to create a response object
from a request object for a given protocol. The processing of the JSP page may
involve creating and/or using other objects.
A JSP page defines a JSP page implementation class that implements the
semantics of the JSP page. This class implements the javax.servlet.Servlet
interface (see Chapter JSP.11 for details). At request time a request intended for
the JSP page is delivered to the JSP page implementation object for processing.
HTTP is the default protocol for requests and responses. Additional request/
response protocols may be supported by JSP containers. The default request and
response objects are of type HttpServletRequest and HttpServletResponse
respectively.
the use of an implicit .jsp extension mapping, or explicitly through the use of a
jsp-group element.
During the translation phase the container locates or creates the JSP page
implementation class that corresponds to a given JSP page. This process is
determined by the semantics of the JSP page. The container interprets the standard
directives and actions, and the custom actions referencing tag libraries used in the
page. A tag library may optionally provide a validation method acting on the
XML View of a JSP page, see below, to validate that a JSP page is correctly using
the library.
A JSP container has flexibility in the details of the JSP page implementation
class that can be used to address quality-of-service--most notably performance--
issues.
During the execution phase the JSP container delivers events to the JSP page
implementation object. The container is responsible for instantiating request and
response objects and invoking the appropriate JSP page implementation object.
Upon completion of processing, the response object is received by the container
for communication to the client. The details of the contract between the JSP page
implementation class and the JSP container are described in Chapter JSP.11.
The translation of a JSP source page into its implementation class can occur at
any time between initial deployment of the JSP page into the JSP container and
the receipt and processing of a client request for the target JSP page.
Section JSP.1.1.9 describes how to perform the translation phase ahead of
deployment.
• The .jsp extension is used only for files corresponding to top level JSP files,
forming a JSP page when processed.
• Statically included segments use any other extension. As included segments
were called ‘JSP fragments’ in past versions of this specification, the extension
.jspf was offered as a suggestion. This extension is still suggested for consis-
tency reasons, despite that they are now called ‘jsp segments’.
JSP documents, that is, JSP pages that are delivered as XML documents, use
the extension .jspx by default.
The jsp-property-group element of web.xml can be used to indicate that some
group of files, perhaps not using either of the extensions above, are JSP pages, and
can also be used to indicate which ones are delivered as XML documents.
• Removal of the start-up lag that occurs when a container must translate a JSP
page upon receipt of the first request.
• Reduction of the footprint needed to run a JSP container, as the Java compiler
is not needed.
Web applications are described in more detail in the Servlet 2.4 specification.
A web application contains a deployment descriptor web.xml that contains
information about the JSP pages, servlets, and other resources used in the web
application. The deployment descriptor is described in detail in the Servlet 2.4
specification.
JSP 2.0 requires that these resources be implicitly associated with and
accessible through a unique ServletContext instance available as the implicit appli-
cation object (see Section JSP.1.8).
The JSP specification uniformly interprets paths in the context of the web
container where the JSP page is deployed. The specification goes through a
mapping translation. The semantics outlined here apply to the translation-time
phase, and to the request-time phase.
Directives
Directives provide global information that is conceptually valid independent
of any specific request received by the JSP page. They provide information for
the translation phase.
Directive elements have a syntax of the form <%@ directive...%>.
Actions
Actions provide information for the request processing phase. The interpreta-
tion of an action may, and often will, depend on the details of the specific
request received by the JSP page. An Actions can either be standard (that is.
defined in this specification), or custom (that is, provided via the portable tag
extension mechanism).
Action elements follow the syntax of an XML element. They have a start tag
including the element name, and may have attributes, an optional body, and a
matching end tag, or may be an empty tag, possibly with attributes:
And:
An element has an element type describing its tag name, its valid attributes
and its semantics. We refer to the type by its tag name.
JSP tags are case-sensitive, as in XML and XHTML.
An action may create objects and may make them available to the scripting
elements through scripting-specific variables.
Scripting Elements
Scripting elements provide “glue” around template text and actions.
JSP 2.0 has a simple Expression Language (EL) that can be used to simplify
accessing data from different sources. EL expressions can be used in JSP stan-
dard and custom actions and template data. EL expressions use the syntax
${expr}; For example:
<mytag attr1=”${bean.property}”.../>
${map[entry]}
<lib:myAction>${3+counter}</lib:myAction>
JSP 2.0 retains the three language-based types of scripting elements: declara-
tions, scriptlets, and expressions. Declarations follow the syntax <%! ... %>.
Scriptlets follow the syntax <% ... %>. Expressions follow the syntax
<%= ... %>.
<x:foo></x:foo>
<x:foo />
<x:foo/>
<x:foo><%-- any comment --%></x:foo>
<foo> </foo>
<foo><%= expression %></foo>
<foo><% scriptlet %></foo>
<foo><bar/></foo>
<foo><!-- a comment --></foo>
It is illegal JSP syntax, which must result in a translation error, to use both an
XML element attribute and a <jsp:attribute> standard action to pass the value of
the same attribute. See Section JSP.5.10 for more details on the <jsp:attribute>
standard action.
The following example uses an XML element attribute to define the value of
the param1 attribute, and uses an attribute standard action to define the value of
the param2 attribute. In this example, the value of param2 comes from the result
of a custom action invocation.
<mytag:paramTag param1=”value1”>
<jsp:attribute name=”param2”>
<mymath:add x=”2” y=”2”/>
</jsp:attribute>
</mytag:paramTag>
If a page author wishes to pass both an attribute standard action and a tag
body, the <jsp:body> standard action must be used to specify the body. A
translation error will result if the custom action invocation has <jsp:attribute>
elements but does not define the body using a <jsp:body> element. See
Section JSP.5.11 for more details on the <jsp:body> standard action.
The following example shows two equivalent tag invocations to the
hypothetical <mytag:formatBody> custom action. The first invocation uses an
XML element attribute to pass the values of the color and size attributes. The
second example uses an attribute standard action to pass the value of the color
attribute. Both examples have tag body containing simply the words “Template
Text”.
<mytag:tagWithBody size=”12”>
<jsp:attribute name=”color”>blue</jsp:attribute>
<jsp:body>
Template Text
</jsp:body>
</mytag:tagWithBody>
<jsp:element name=”H${headLevel}”>
<jsp:attribute name=”size”>${headSize}</jsp:attribute>
<jsp:body>${headText}<jsp:body>
</jsp:element>
The result is
The next two tables show another example, with input and output.,
The result is
http://www.w3c.org/TR/2000/REC-xml-20001006#sec-notation
• Many productions make use of XML-style attributes. These attributes can ap-
pear in any order, separated from each other by whitespace, but no attribute
can be repeated more than once. To make these XML-style attribute specifica-
tions more concise and easier to read, the syntax ATTR[attrset] is used in the
EBNF to define a set of XML attributes that are recognized in a particular pro-
duction.
Within the square brackets (attrset) is listed a comma-separated list of case-
sensitive attribute names that are valid. Each attribute name represents a sin-
gle XML attribute. If the attribute name is prefixed with an =, the production
Attribute (defined below) must be matched (either a rtexprvalue or a static
value is accepted). If not, the production NonRTAttribute must be matched
(only static values are accepted). If the attribute name is prefixed with a !, the
attribute is required and must appear in order for this production to be
matched. If an attribute that matches the Attribute production with a name not
listed appears adjacent to any of the other attributes, the production is not
matched.
JSPDirectiveBody ::= S?
( ( ‘page’ S PageDirectiveAttrList )
| ( ‘taglib’ S TagLibDirectiveAttrList )
| ( ‘include’ S IncludeDirectiveAttrList )
)
S? ‘%>’
| <TRANSLATION_ERROR>
XMLJSPDirectiveBody::= S?
( ( ‘page’ S PageDirectiveAttrList S?
( ‘/>’ | ( ‘>’ S? ETag ) )
)
| ( ‘include’ S IncludeDirectiveAttrList S?
( ‘/>’ | ( ‘>’ S? ETag ) )
)
)
| <TRANSLATION_ERROR>
TagDefDirectiveBody::= S?
( ( ‘tag’ S TagDirectiveAttrList )
| ( ‘taglib’ S TagLibDirectiveAttrList )
| ( ‘include’ S IncludeDirectiveAttrList )
| ( ‘attribute’ S AttributeDirectiveAttrList )
| ( ‘variable’ S VariableDirectiveAttrList )
)
S? ‘%>’
| <TRANSLATION_ERROR>
IncludeDirectiveAttrList::=ATTR[ !file ]
XMLDeclarationBody::= ( S? ‘/>’ )
| ( S? ‘>’
( ( Char* - ( Char* ‘<‘ ) ) CDSect? )*
ETag
)
| <TRANSLATION_ERROR>
XMLExpressionBody::= ( S? ‘/>’ )
| ( S? ‘>’
( ( Char* - ( Char* ‘<’ ) ) CDSect? )*
ETag
)
| <TRANSLATION_ERROR>
[ vc: ExpressionBodyContent ]
ScriptlessActionBody::= JspAttributeAndBody
| ( ‘>’ ScriptlessBody ETag )
ScriptlessOptionalBody::=EmptyBody | ScriptlessActionBody
CustomActionTagDependent::= TagDependentOptionalBody
[vc: CustomActionTagDependentMatch]
CustomActionJSPContent::= OptionalBody
[ vc: CustomActionJSPContentMatch ]
CustomActionScriptlessContent::= ScriptlessOptionalBody
[ vc: CustomActionScriptlessContentMatch ]
S ::= XML::S
Eq ::= XML::Eq
tered TagLibDirectiveAttrList with prefix matching the TagPrefix for this poten-
tial custom action, or nil if no such TagLibDirectiveAttrList was encountered in
this translation unit.
■
If U is not nil, let L be the <taglib> element in the relevant TLD entry such that
L.uri is equal to U.
Then:
■
If, after being parsed, the CustomAction production is matched (not yet tak-
ing into account the following rules), TagPrefix is considered a potential Tag-
Prefix in this translation unit for the purposes of the
TagLibDirectiveUniquePrefix validity constraint.
■
The CustomAction production will not be matched if U is nil or if the TagPre-
fix does not match the prefix AttributeValue of a TagLibDirectiveAttrList previ-
ously encountered in this translation unit.
■
Otherwise, if the CustomAction production is matched, a translation error
will result if there does not exist a <tag> element T in a relevant TLD such
that L.T.name is equal to CustomActionName.
• CustomActionTagDependentMatch - Assume the definition of L from the Cus-
tomActionMatchesAndValid validity constraint above. The CustomAction-
TagDependent production is not matched if there does not exist a <tag>
element T in a relevant TLD such that L.T.body-content contains the value
tagdependent.
el, or if there is no corresponding nesting level (i.e. too many closing tags).
This is similar to the way XML is defined, except that template text that looks
like a closing element with an unrecognized prefix is allowed in the body of a
custom or standard action. In the following example, assuming ‘my’ is a valid
prefix and ‘indent’ is a valid tag, the </ul> tag is considered template text, and
no translation error is produced:
<my:indent level=”2”>
</ul>
</my:indent>
<my:indent level=”2”>
</my:othertag>
</my:indent>
attribute combination to be matched selects the valid body production for this
standard action invocation.
Table JSP.1-5 Valid body content and attributes for Standard Actions
Element Body Production Valid Attribute Combinations
Errors may occur at translation time or at request time. This section describes
how errors are treated by a compliant implementation.
1.
Note that this is independent of scripting language. This specification re-
quires that unhandled errors occurring in a scripting language environ-
ment used in a JSP container implementation to be signalled to the JSP
page implementation class via the Java programming language exception
mechanism.
JSP.1.5 Comments
There are two types of comments in a JSP page: comments to the JSP page
itself, documenting what the page is doing; and comments that are intended to
appear in the generated document sent to the client.
The body of the content is ignored completely. Comments are useful for
documentation but also are used to “comment out” some portions of a JSP page.
Note that JSP comments do not nest.
An alternative way to place a comment in JSP is to use the comment
mechanism of the scripting language. For example:
Note – The current quoting rules do not allow for quoting special characters
such as \n - the only current way to do this in a JSP is with a Java expression.
Quoting in EL Expressions
■
There is no special quoting mechanism within EL expressions; use a literal
‘${‘ if the literal ${ is desired and expressions are enabled for the page. For
example, the evaluation of ${‘${‘} is ‘${‘. Note that ${‘}’} is legal, and simply
evaluates to ‘}’.
Quoting in Attributes
Quotation is done consistently regardless of whether the attribute value is a
literal or a request-time attribute expression. Quoting can be used in attribute
values regardless of whether they are delimited using single or double quotes. It is
only required as described below.
■
A ‘ is quoted as \’. This is required within a single quote-delimited attribute
value.
■
A “ is quoted as \”. This is required within a double quote-delimited attribute
value.
■
A \ is quoted as \\
■
Only when the EL is enabled for a page (see Section JSP.3.3.2, “Deactivating
EL Evaluation”), a literal $ can be quoted by \$. This is not required but is
useful for quoting EL expressions.
■
A %> is quoted as %\>
■
A <% is quoted as <\%
■
The entities ' and " are available to describe single and double
quotes.
Examples
The following line shows an illegal attribute values.
The following line shows a legal scriptlet, but perhaps with an intended value.
The result is Joe said %\> not Joe said %>.
XML Documents
The quoting conventions are different from those of XML. See Chapter JSP.6.
• Initially, out is a new JspWriter object. This object may be different from the
stream object returned from response.getWriter(), and may be considered to be
interposed on the latter in order to implement buffering (see
Section JSP.1.10.1, “The page Directive”). This is the initial out object. JSP
page authors are prohibited from writing directly to either the PrintWriter or
OutputStream associated with the ServletResponse.
• The JSP container should not invoke response.getWriter() until the time when
the first portion of the content is to be sent to the client. This enables a number
of uses of JSP, including using JSP as a language to “glue” actions that deliver
A JSP page can also describe what should happen when some specific events
occur. In JSP 2.0, the only events that can be described are the initialization and
the destruction of the page. These events are described using “well-known method
names” in declaration elements. (See Section JSP.11.1.1.1).
JSP.1.8 Objects
A JSP page can access, create, and modify server-side objects. Objects can be
made visible to actions, EL expressions and to scripting elements. An object has a
scope describing what entities can access the object.
Actions can access objects using a name in the PageContext object.
An object exposed through a scripting variable has a scope within the page.
Scripting elements can access some objects directly via a scripting variable. Some
implicit objects are visible via scripting variables and EL expressions in any JSP
page.
An element type indicates the name and type of such variables although
details on the name of the variable may depend on the Scripting Language. The
scripting language may also affect how different features of the object are
exposed. For example, in the JavaBeans specification, properties are exposed via
getter and setter methods, while these properties are available directly as variables
in the JavaScript™ programming language.
The exact rules for the visibility of the variables are scripting language
specific. Chapter JSP.1.1 defines the rules for when the language attribute of the
page directive is java.
• page - Objects with page scope are accessible only within the page where they
are created. All references to such an object shall be released after the response
is sent back to the client from the JSP page or the request is forwarded some-
where else. References to objects with page scope are stored in the pageCon-
text object.
• request - Objects with request scope are accessible from pages processing the
same request where they were created. References to the object shall be re-
leased after the request is processed. In particular, if the request is forwarded
to a resource in the same runtime, the object is still reachable. References to
objects with request scope are stored in the request object.
• session - Objects with session scope are accessible from pages processing re-
quests that are in the same session as the one in which they were created. It is
not legal to define an object with session scope from within a page that is not
A name should refer to a unique object at all points in the execution; that is,
all the different scopes really should behave as a single name space. A JSP
container implementation may or may not enforce this rule explicitly for
performance reasons.
Variable
Name Type Semantics & Scope
Variable
Name Type Semantics & Scope
a. When the scripting language is java then page is a synonym for this in the
body of the page.
Variable
Name Type Semantics & Scope
Object names with prefixes jsp, _jsp, jspx and _jspx, in any combination of
upper and lower case, are reserved by the JSP specification.
See Section JSP.7.5.1 for some non-normative conventions for the
introduction of new implicit objects.
The semantics of template (or uninterpreted) Text is very simple: the template
text is passed through to the current out JspWriter implicit object, after applying the
substitutions of Section JSP.1.6, “Quoting and Escape Conventions”.
JSP.1.10 Directives
Directives are messages to the JSP container. Directives have this syntax:
There may be optional white space after the <%@ and before %>.
Examples
The following directive provides some user-visible information on this JSP
page:
The following directive indicates that the scripting language is based on Java,
that the types declared in the package com.myco are directly available to the
scripting code, and that a buffering of 16KB should be used.
Syntax
<%@ page page_directive_attr_list %>
pageEncoding Describes the character encoding for the JSP page. The value
is of the form “CHARSET”, which must be the IANA name
for a character encoding. For JSP pages in standard syntax,
the character encoding for the JSP page is the charset given
by the pageEncoding attriute if it is present, otherwise the
charset given by the contentType attribute if it is present,
otherwise “ISO-8859-1”.
For JSP documents in XML syntax, the character encoding
for the JSP page is determined as described in section 4.3.3
and appendix F.1 of the XML specification. The pageEncod-
ing attribute is not needed for such documents. It is a
translation-time error if a document names different
encodings in its XML prolog / text declaration and in the
pageEncoding attribute. The corresponding JSP
configuration element is page-encoding (see
Section JSP.3.3.4, “Declaring Page Encodings”).
See Chapter JSP.4 for complete details on character
encodings.
isELIgnored Defines whether EL expressions are ignored or evaluated for
this page and translation unit. If true, EL expressions (of the
form ${...}) are ignored by the container. If false, EL
expressions (of the form ${...}) are evaluated when they
appear in template text or action attributes. The
corresponding JSP configuration element is el-ignored (see
Section JSP.3.3.2). The default value varies depending on the
web.xml version - see Section JSP.2.2.4, “Deactivating EL
Evaluation”.
Examples
In the following example, a tag library is introduced and made available to
this page using the super prefix; no other tag libraries should be introduced in
this page using this prefix. In this particular case, we assume the tag library
includes a doMagic element type, which is used within the page.
<%@ taglib uri=”http://www.mycorp/supertags” prefix=”super” %>
...
<super:doMagic>
...
</super:doMagic>
Syntax
<%@ taglib ( uri=”tagLibraryURI” | tagdir=”tagDir” ) prefix=”tagPrefix” %>
Table JSP.1-9
uri Either an absolute URI or a relative URI specification that
uniquely identifies the tag library descriptor associated with
this prefix.
The URI is used to locate a description of the tag library as
indicated in Chapter 7.
Table JSP.1-9
A fatal translation-time error will result if the JSP page translator encounters a
tag with name prefix: Name using a prefix that is introduced using the taglib
directive, and Name is not recognized by the corresponding tag library.
Examples
The following example requests the inclusion, at translation time, of a copy-
right file. The file may have elements which will be processed too.
Syntax
<%@ include file="relativeURLspec" %>
The Spec column describes what type of specification is valid to appear in the
given element. The JSP specification requires a relative URL spec. The reference
is resolved by the web/application server and its URL map is involved. Include
directives are interpreted relative to the current JSP file; jsp:include actions are
interpreted relative to the current JSP page.
An include directive regards a resource like a JSP page as a static object; i.e.
the text in the JSP page is included. An include action regards a resource like a
JSP page as a dynamic object; i.e. the request is sent to that object and the result of
processing it is included.
Implicit include directives can also be requested for a collection of pages
through the use of the <include-prelude> and <include-coda> elements of the JSP
configuration section of web.xml.
For translation-time includes, included content can use either the same syntax
as the including page, or a different syntax. For example, a JSP file written in the
standard JSP syntax can include a JSP file written using the XML syntax. The
following semantics for translation-time includes apply:
• The JSP container must detect the syntax for each JSP file individually and
parse each JSP file according to the syntax in which it is written.
• A JSP file written using the XML syntax must be well-formed according to
the "XML" and "Namespaces in XML" specifications, otherwise a translation
error must occur.
• When including a JSP document (written in the XML syntax), in the resulting
XML View of the translation unit the root element of the included segment
must have the default namespace reset to "". This is so that any namespaces
associated with the empty prefix in the including document are not carried
over to the included document.
• When a taglib directive is encountered in a standard syntax page, the
namespace is applied globally, and is added to the <jsp:root> element of the
resulting XML View of the translation unit.
• If a taglib directive is encountered in a standard syntax page that attempts to
redefine a prefix that is already defined in the current scope (by a JSP segment
in either syntax), a translation error must occur unless that prefix is being re-
defined to the same namespace URI.
See Section JSP.10.3 for examples of how these semantics are applied to
actual JSP pages and documents.
JSP.1.11 EL Elements
All JSP containers must support scripting elements based on the Java
programming language. Additionally, JSP containers may also support other
scripting languages. All such scripting languages must support:
The precise definition of the semantics for scripting done using elements
based on the Java programming language is given in Chapter JSP.9.
The semantics for other scripting languages are not precisely defined in this
version of the specification, which means that portability across implementations
cannot be guaranteed. Precise definitions may be given for other languages in the
future.
Each scripting element has a <%-based syntax as follows:
White space is optional after <%!, <%, and <%=, and before %>.
The equivalent XML elements for these scripting elements are described in
Section JSP.6.3.7.
JSP.1.12.1 Declarations
Declarations are used to declare variables and methods in the scripting language
used in a JSP page. A declaration must be a complete declarative statement, or
sequence thereof, according to the syntax of the scripting language specified.
Declarations do not produce any output into the current out stream.
Declarations are initialized when the JSP page is initialized and are made
available to other declarations, scriptlets, and expressions.
The <jsp:declaration> element (Section JSP.6.3.7) describes the same
information following the XML syntax.
Examples
For example, the first declaration below declares an integer, global to the
page. The second declaration does the same and initializes it to zero. This type
of initialization should be done with care in the presence of multiple requests
JavaServer Pages 2.0 Specification
1-56 CORE SYNTAX AND SEMANTICS
on the page. The third declaration declares a method global to the page.
Syntax
<%! declaration(s) %>
JSP.1.12.2 Scriptlets
Scriptlets can contain any code fragments that are valid for the scripting lan-
guage specified in the language attribute of the page directive. Whether the code
fragment is legal depends on the details of the scripting language (see
Chapter JSP.9).
Scriptlets are executed at request-processing time. Whether or not they
produce any output into the out stream depends on the code in the scriptlet.
Scriptlets can have side-effects, modifying the objects visible to them.
When all scriptlet fragments in a given translation unit are combined in the
order they appear in the JSP page, they must yield a valid statement, or sequence
of statements, in the specified scripting language.
To use the %> character sequence as literal characters in a scriptlet, rather
than to end the scriptlet, escape them by typing %\>.
The <jsp:scriptlet> element (Section JSP.6.3.7) describes the same information
following the XML syntax.
Examples
Here is a simple example where the page changed dynamically depending on
the time of day.
A scriptlet can also have a local variable declaration, for example the following
scriptlet just declares and initializes an integer, and later increments it.
Syntax
<% scriptlet %>
JSP.1.12.3 Expressions
An expression element in a JSP page is a scripting language expression that is
evaluated and the result is coerced to a String. The result is subsequently emitted
into the current out JspWriter object.
If the result of the expression cannot be coerced to a String the following must
happen: If the problem is detected at translation time, a translation time error shall
occur. If the coercion cannot be detected during translation, a ClassCastException
shall be raised at request time.
A scripting language may support side-effects in expressions when the
expression is evaluated. Expressions are evaluated left-to-right in the JSP page. If
an expression appears in more than one run-time attribute, they are evaluated left-
to-right in the tag. An expression might change the value of the out object,
although this is not something to be done lightly.
The expression must be a complete expression in the scripting language in
which it is written, or a translation error must occur.
Expressions are evaluated at request processing time. The value of an
expression is converted to a String and inserted at the proper position in the .jsp
file.
The <jsp:expression> element (Section JSP.6.3.7) describes the same
information following the XML syntax.
Examples
This example inserts the current date.
Syntax
<%= expression %>
JSP.1.13 Actions
Actions may affect the current out stream and use, modify and/or create objects.
Actions may depend on the details of the specific request object received by the JSP
page.
The JSP specification includes some actions that are standard and must be
implemented by all conforming JSP containers; these actions are described in
Chapter 5.
New actions are defined according to the mechanisms described in Chapters 7
and 13 and are introduced using the taglib directive.
The syntax for action elements is based on XML. Actions can be empty or
non-empty.
The interpretation of all actions start by evaluating the values given to its
attributes left to right, and assigning the values to the attributes. In the process some
conversions may be applicable; the rules for them are described in
Section JSP.1.14.2.
Many values are fixed translation-time values, but JSP 2.0 also provides a
mechanism for describing values that are computed at request time, the rules are
described in Section JSP.1.14.1.
These conversions are part of the generic mechanism used to assign values
to attributes of actions: when an attribute value that is not a request-time
This chapter describes the expression language used by JSP 2.0. The expres-
sioin language is independent of JSP details except for the set of implicit objects.
The language was initially defined by the JSP StandardTag Library (JSTL) 1.0
specification, but is now incorporated in the JSP specification, and extended with
new features. A JSTL maintenance release (JSTL 1.1) aligns itself with the JSP
2.0 version of the language. The JavaServer Faces expert group (JSR-127) is also
considering to use this expression language.
The language semantics are exposed through an API described in the
javax.servlet.jsp.el package. The main use of this API is to implement the JSP 2.0
language in a JSP container, but it may be used by JSP developers, most likely tag
hander authors.
Sections JSP.2.1 and JSP.2.2 describe how the expression language is used in
JSP 2.0 while sections JSP.2.3 to JSP.2.9 provide the generic description of the
expression language. The API to the expression language is described in full in
Chapter JSP.14.
JSP.2.1 Overview
The expression language is used in a number of places within the JSP 2.0 lan-
guage.
<some:tag value="${expr}"/>
In this case, the expression is evaluated and the result is coerced to the at-
tribute's expected type according to the type conversion rules described later.
• The attribute value contains one or more expressions separated or surrounded
by text:
<some:tag value="some${expr}${expr}text${expr}"/>
In this case, the expressions are evaluated from left to right, coerced to Strings
(according to the type conversion rules described later), and concatenated
with any intervening text. The resulting String is then coerced to the attribute's
expected type according to the type conversion rules described later.
• The attribute value contains only text:
<some:tag value="sometext"/>
In this case, the attribute's String value is coerced to the attribute's expected
type according to the type conversion rules described in Section JSP.2.8.
These rules are equivalent to the JSP 1.2 conversions, except that empty
strings are treated differently.
JSP.2.2.1.1 Examples
The following shows a conditional action that uses the EL to test whether a
property of a bean is less than 3.
Note that the normal JSP coercion mechanism already allows for:
There may be literal values that include the character sequence ${. If that is
the case, a literal with that value can be used as shown here:
The resulting attribute value would then be the string an expression is ${expr}.
JSP.2.2.2.1 Examples
The following shows a custom action where two EL expressions are used to
access bean properties:
<c:wombat>
One value is ${bean1.a} and another is ${bean2.a.c}
</c:wombat>
• header - a Map that maps header names to a single String header value (ob-
tained by calling ServletRequest.getHeader(String name))
• headerValues - a Map that maps header names to a String[] of all values for
that header (obtained by calling ServletRequest.getHeaders(String))
• cookie - a Map that maps cookie names to a single Cookie object. Cookies are
retrieved according to the semantics of HttpServletRequest.getCookies(). If the
same name is shared by multiple cookies, an implementation must use the
first one encountered in the array of Cookie objects returned by the getCook-
ies() method. However, users of the cookie implicit object must be aware that
the ordering of cookies is currently unspecified in the servlet specification.
The following table shows some examples of using these implicit objects:
Expression Result
JSP.2.3.1 Overview
The syntax is quite simple. Variables are accessed by name. A generalized []
operator can be used to access maps, lists, arrays of objects and properties of a Java-
Beans object; the operator can be nested arbitrarily. The . operator can be used as a
convenient shorthand for property access when the property name follows the con-
ventions of Java identifiers, but the [] operator allows for more generalized access.
Relational comparisons are allowed using the standard Java relational
operators. Comparisons may be made against other values, or against boolean (for
equality comparisons only), String, integer, or floating point literals. Arithmetic
operators can be used to compute integer and floating point vlaues. Logical
operators are available.
JSP.2.3.2 Literals
There are literals for boolean, integer, floating point, string, null.
• Addition: +
• Substraction: -
• Multiplication: *
• Division: / and div
• Remainder (modulo): % and mod
The last two operators are available in both syntaxes to be consistent with
XPath and ECMAScript.
The evaluation of arithmetic operators is described in the following sections.
A and B are the evaluation of subexpressions
• == and eq
• != and ne
• < and lt
• > and gt
• <= and le
• >= and ge
The second versions of the last 4 operators are made available to avoid having
to use entity references in XML syntax and have the exact same behavior, i.e. <
behaves the same as lt and so on.
The evaluation of relational operators is described in the following sections.
JSP.2.3.5.6 A {<,>,<=,>=,lt,gt,le,ge} B
• If A==B, if operator is <=, le, >=, or ge return true. Otherwise return false
• If A is null or B is null, return false
• If A or B is BigDecimal, coerce both A and B to BigDecimal and use the return
value of A.compareTo( B ).
• If A or B is Float or Double coerce both A and B to Double apply operator
• If A or B is BigInteger, coerce both A and B to BigInteger and use the return
value of A.compareTo( B ).
• If A or B is Byte, Short, Character, Integer, or Long coerce both A and B to
Long and apply operator
JSP.2.3.5.7 A {==,!=,eq,ne} B
• Coerce A to Boolean:
■
If A is true, evaluate and return B
■
If A is false, evaluate and return C
JSP.2.3.9 Parentheses
Parentheses can be used to change precedence, as in: ${ ( a * (b + c) ) }
• [] .
• ()
• - (unary) not ! empty
• * / div % mod
• + - (binary)
• < > <= >= lt gt le ge
• == != eq ne
• && and
• || or
• ?:
The following words are reserved for the language and should not be used as
identifiers.
Note that many of these words are not in the language now, but they may be in
the future, so developers should avoid using these words now.
A core concept in the EL is the evaluation of a variable name into an object. The
EL API provides a generalized mechanism, a VariableResolver, that will resolve
names into objects. The default resolver is what is used in the evaluation of EL
expressions in template and attributes. This default resolver provides the implicit
objects mentioned in Section JSP.2.2.3. The default resolver also provides a map for
other identifiers by looking up its value as an attribute, according to the behavior of
PageContext.findAttribute(String) on the pageContext object. For example:
${product}
This expression will look for the attribute named product, searching the page,
request, session, and application scopes, and will return its value. If the attribute is
not found, null is returned.
Note that an identifier that matches one of the implicit objects described in the
next section will return that implicit object instead of an attribute value.
See Chapter JSP.14 for further details on the VariableResolver and how it fits
with the evaluation API.
JSP.2.6 Functions
The EL has qualified functions, reusing the notion of qualification from XML
namespaces (and attributes), XSL functions, and JSP custom actions. Functions
are mapped to public static methods in Java classes. In JSP 2.0 the map is
specified in the TLD.
As with the rest of EL, this element can appear in attributes and directly in
template text.
The prefix ns must match the prefix of a tag library that contains a function
whose name and signature matches the function being invoked (f), or a translation
error must occur. If the prefix is omitted, the tag library associated with the default
namespace is used (this is only possible in JSP documents).
In the following standard syntax example, func1 is associated with some-
taglib:
In the following JSP document example, both func2 and func3 are associated
with default-taglib:
<some:tag xmlns=”http://acme.com/default-taglib”
xmlns:some=”http://acme.com/some-taglib”
xmlns:jsp=”http://java.sun.com/JSP/Page”>
<some:other value=”${func2(true)}”>
${func3(true)}
</some:other>
</some:tag>
A tag library can have only one function element in the same tag library with
the same value for their name element. If two functions have the same name, a
translation-time error shall be generated.
Reference the function element in Section JSP.C.1, “XML Schema for TLD,
JSP 2.0” for how to specify a function in the TLD.
JSP.2.6.3 Example
The following TLD fragment describes a function with name nickname that is
intended to fetch the nickname of the user:
<taglib>
...
<function>
<name>nickname</name>
<function-class>mypkg.MyFunctions</function-class>
<function-signature>
java.lang.String nickName(java.lang.String)
</function-signature>
</function>
</taglib>
<h2>Dear ${my:nickname(user)}</h2>
JSP.2.6.4 Semantics
• If the function has no prefix, the default namespace is used. If the function has
a prefix, assume the namespace as that associated with the prefix.
Let ns be the namespace associated with the function, and f be the name of the
function.
• Locate the TLD associated with ns. If none can be found, this shall be a trans-
lation-time error.
• Locate the function element with a name subelement with value f in that TLD.
If none can be found, this shall be a translation-time error.
• Locate the public class with name equal to the value of the function-class ele-
ment. Locate the public static method with name and signature equal to the
The EL defines a set of implicit objects which depends on the context in which
the EL is being used. When an expression references one of these objects by name,
the appropriate object is returned instead of the corresponding attribute. For exam-
ple in the context of JSP pages, ${pageContext} returns the PageContext object,
even if there is an existing pageContext attribute containing some other value. See
Section JSP.2.2.3 for details.
For example, if coercing an int to a String, "box" the int into an Integer and
apply the rule for coercing an Integer to a String. Or if coercing a String to a dou-
ble, apply the rule for coercing a String to a Double, then "unbox" the resulting
Double, making sure the resulting Double isn’t actually null.
• If A is String: return A
• Otherwise, if A is null: return ""
• Otherwise, if A.toString() throws an exception, error
• Otherwise, return A.toString()
• If A is String, then:
■
If N is BigDecimal then:
• If new BigDecimal( A ) throws an exception then error.
• Otherwise, return new BigDecimal( A ).
■
If N is BigInteger then:
• If new BigInteger( A ) throws an exception then error.
• Otherwise, return new BigInteger( A ).
■
If N.valueOf( A ) throws an exception, then error.
■
Otherwise, return N.valueOf( A ).
• Otherwise, error.
Notes
The web.xml file can include an explicit taglib map between URIs and TLD
resource paths described using taglib elements in the Web Application Deployment
descriptor.
The taglib element is a subelement of jsp-config that can be used to provide
information on a tag library that is used by a JSP page within the Web
Application. The taglib element has two subelements: taglib-uri and taglib-location.
A taglib-uri element describes a URI identifying a tag library used in the web
application. The body of the taglib-uri element may be either an absolute URI
specification, or a relative URI as in Section JSP.1.2.1. There should be no
entries in web.xml with the same taglib-uri value.
A taglib-location element contains a resource location (as indicated in
Section JSP.1.2.1) of the Tag Library Description File for the tag library.
A JSP property group is a collection of properties that apply to a set of files that
represent JSP pages. These properties are defined in one or more jsp-property-group
elements in the Web Application deployment descriptor.
Most properties defined in a JSP property group apply to an entire translation
unit, that is, the requested JSP file that is matched by its URL pattern and all the
files it includes via the include directive. The exception is the page-encoding
property, which applies separately to each JSP file matched by its URL pattern.
The applicability of a JSP property group is defined through one or more URL
patterns. URL patterns use the same syntax as defined in Chapter SRV.11 of the
Servlet 2.4 specification, but are bound at translation time. All the properties in
the group apply to the resources in the Web Application that match any of the
URL patterns. There is an implicit property: that of being a JSP file. JSP Property
Groups do not affect tag files.
If a resource matches a URL pattern in both a <servlet-mapping> and a <jsp-
property-group>, the pattern that is most specific applies (following the same rules
as in the Servlet specification). If the URL patterns are identical, the <jsp-property-
group> takes precedence over the <servlet-mapping>. If at least one <jsp-property-
group> contains the most specific matching URL pattern, the resource is
considered to be a JSP file, and the properties in that <jsp-property-group> apply.
In addition, if a resource is considered to be a JSP file, all include-prelude and
include-coda properties apply from all the <jsp-property-group> elements with
matching URL patterns (see Section JSP.3.3.5).
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
Page authors can override the default mode through the isELIgnored attribute
of the page directive. For tag files, there is no default, but the isELIgnored attribute
of the tag directive can be used to control the EL evaluation settings.
Table JSP.3-1 summarizes the EL evaluation settings for JSP pages, and their
meanings:
Table JSP.3-2 summarizes the EL evaluation settings for tag files, and their
meanings:
Tag Directive
isELIgnored EL Encountered
unspecified Evaluated
false Evaluated
true Ignored
The EL evaluation setting for a translation unit also affects whether the \$
quote sequence is enabled for template text and attribute values in a JSP page,
document, or tag file. When EL evaluation is disabled, \$ will not be recognized as
a quote, whereas when EL evaluation is enabled, \$ will be recognized as a quote
for $. See Section JSP.1.6, “Quoting and Escape Conventions” and
Section JSP.6.2.2, “Overview of Syntax of JSP Documents” for details.
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
JSP Configuration
<scripting-invalid> Scripting Encountered
unspecified Valid
false Valid
<jsp-property-group>
<url-pattern>/ja/*</url-pattern>
<page-encoding>Shift_JIS</page-encoding>
</jsp-property-group>
For example, the following web.xml fragment defines two groups. Together
they indicate that everything in directory /two/ have /WEB-INF/jspf/prelude1.jspf
and /WEB-INF/jspf/prelude2.jspf at the beginning and /WEB-INF/jspf/coda1.jspf and
/WEB-INF/jspf/coda2.jspf at the end, in that order, while other .jsp files only have
/WEB-INF/jspf/prelude1.jspf at the beginning and /WEB-INF/jspf/coda1.jspf at the
end.
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<include-prelude>/WEB-INF/jspf/prelude1.jspf</include-prelude>
<include-coda>/WEB-INF/jspf/coda1.jspf</include-coda>
</jsp-property-group>
<jsp-property-group>
<url-pattern>/two/*</url-pattern>
<include-prelude>/WEB-INF/jspf/prelude2.jspf</include-prelude>
<include-coda>/WEB-INF/jspf/coda2.jspf</include-coda>
</jsp-property-group>
<jsp-property-group>
<url-pattern>*.jspx</url-pattern>
<is-xml>false</is-xml>
</jsp-property-group>
<jsp-property-group>
<url-pattern>*.svg</url-pattern>
<is-xml>true</is-xml>
</jsp-property-group>
http://java.sun.com/j2se/1.3/docs/guide/intl/encoding.doc.html
http://java.sun.com/j2se/1.4/docs/guide/intl/encoding.doc.html
http://www.iana.org/assignments/character-sets
The page character encoding is the character encoding in which the JSP page or
tag file itself is encoded. The character encoding is determined for each file sepa-
rately, even if one file includes another using the include directive
(Section JSP.1.10.3). A detailed algorithm for determining the page character
encoding of a JSP page or tag file can be found in Appendix JSP.D.
For JSP pages in standard syntax, the page character encoding is determined
from the following sources:
The response character encoding is the character encoding of the response gen-
erated from a JSP page, if that response is in the form of text. It is primarily man-
aged as the javax.servlet.ServletResponse object’s characterEncoding property.
The JSP container determines an initial response character encoding along
with the initial content type for a JSP page and calls ServletResponse.setContent-
Type() with this information before processing the page. JSP pages can set initial
content type and initial response character encoding using the contentType
attribute of the page directive.
The initial response content type is set to the TYPE value of the contentType
attribute of the page directive. If the page doesn’t provide this attribute, the initial
content type is “text/html” for JSP pages in standard syntax and “text/xml” for JSP
documents in XML syntax.
The initial response character encoding is set to the CHARSET value of the
contentType attribute of the page directive. If the page doesn’t provide this
attribute or the attribute doesn’t have a CHARSET value, the initial response
character encoding is determined as follows:
After the initial response character encoding has been set, the JSP page’s
content can dynamically modify it by calling the ServletResponse object’s set-
CharacterEncoding and setLocale methods directly or indirectly. A number of
JSTL internationalization and formatting actions call ServletResponse.setLo-
cale(), which may affect the response character encoding. See the Servlet and
JSTL specifications for more information.
Note that the response character encoding can only be changed until the
response is committed. Data is sent to the response stream on buffer flushes for
buffered pages, or on encountering the first content (beware of whitespace) on
unbuffered pages. Whitespace is notoriously tricky for JSP Pages in JSP syntax,
but much more manageable for JSP Documents in XML syntax.
The XML view character encoding is the character encoding used for external-
izing the XML view of a JSP page or tag file.
The XML view character encoding is always UTF-8.
The JSP specification does not mandate any specific approach for structuring
localized content, and different approaches are possible. Two common approaches
are to use a template taglib and pull localized strings from a resource repository, or
to use-per-locale JSP pages. Each approach has benefits and drawbacks. The JSTL
internationalization and formatting actions provide support for retrieving localized
content from resource bundles and thus support the first approach. Some users have
been using transformations on JSP documents to do simple replacement of elements
by localized strings, thus maintaining JSP syntax with no performance cost at run-
time. Combinations of these approaches also make sense.
This chapter describes the standard actions of JavaServer Pages 2.0 (JSP 2.0).
Standard actions are represented using XML elements with a prefix of jsp (though
that prefix can be redefined in the XML syntax). A translation error will result if the
JSP prefix is used for an element that is not a standard action.
JSP.5.1 <jsp:useBean>
or the name of a resource of the form a/b/c.ser that will be resolved in the current
ClassLoader. If this is not true, a request-time exception, as indicated in the
semantics of the instantiate method will be raised. The value of this attribute can
be a request-time attribute expression.
The id Attribute
The id=”name” attribute/value tuple in a jsp:useBean action has special meaning
to a JSP container, at page translation time and at client request processing time. In
particular:
• the name must be unique within the translation unit, and identifies the particu-
lar element in which it appears to the JSP container and page.
Duplicate id’s found in the same translation unit shall result in a fatal transla-
tion error.
• The JSP container will associate an object (a JavaBean component) with the
named value and accessed via that name in various contexts through the page-
context object described later in this specification.
The name is also used to expose a variable (name) in the page’s scripting lan-
guage environment. The scope of the scripting language variable is dependent
upon the scoping rules and capabilities of the scripting language used in the
page.
Note that this implies the name value syntax must comply with the variable
naming syntax rules of the scripting language used in the page. Chapter JSP.9
provides details for the case where the language attribute is java.
<%
/*
* the tag above creates or obtains the Customer Bean
* reference, associates it with the name “customer” in the
* PageContext, and declares a Java programming language
* variable of the same name initialized to the object reference
* in this block’s scope.
*/
%>
...
<%= customer.getName(); %>
...
<% } // close the block %>
<%
// the variable customer is out of scope now but
// the object is still valid (and accessible via pageContext)
%>
Semantics
The actions performed in a jsp:useBean action are:
1. An attempt to locate an object based on the attribute values id and scope. The
inspection is done synchronized per scope namespace to avoid non-determin-
istic behavior.
2. A scripting language variable of the specified type (if given) or class (if type
is not given) is defined with the given id in the current lexical scope of the
scripting language. The type attribute should be used to specify a Java type that
cannot be instantiated as a JavaBean (i.e. a Java type that is an abstract class,
interface, or a class with no public no-args constructor). If the class attribute is
used for a Java type that cannot be instantiated as a JavaBean, the container
may consider the page invalid, and is recommended to (but not required to)
produce a fatal translation error at translation time, or a java.lang.Instantiation-
Exception at request time. Similarly, if either type or class specify a type that
can not be found, the container may consider the page invalid, and is recom-
mended to (but not required to) produce a fatal translation error at translation
time, or a java.lang.ClassNotFoundException at request time.
3. If the object is found, the variable’s value is initialized with a reference to the
located object, cast to the specified type. If the cast fails, a java.lang.ClassCas-
tException shall occur. This completes the processing of this jsp:useBean ac-
tion.
4. If the jsp:useBean action had a non-empty body it is ignored. This completes
the processing of this jsp:useBean action.
5. If the object is not found in the specified scope and neither class nor beanName
are given, a java.lang.InstantiationException shall occur. This completes the
processing of this jsp:useBean action.
6. If the object is not found in the specified scope, and the class specified names
a non-abstract class that defines a public no-args constructor, then the class is
instantiated. The new object reference is associated with the scripting variable
and with the specified name in the specified scope using the appropriate scope
dependent association mechanism (see PageContext). After this, step 8 is per-
formed.
If the object is not found, and the class is either abstract, an interface, or no pub-
lic no-args constructor is defined therein, then a java.lang.InstantiationExcep-
tion shall occur. This completes the processing of this jsp:useBean action.
7. If the object is not found in the specified scope; and beanName is given, then
the method instantiate of java.beans.Beans will be invoked with the ClassLoad-
er of the servlet object and the beanName as arguments. If the method suc-
ceeds, the new object reference is associated the with the scripting variable and
with the specified name in the specified scope using the appropriate scope de-
pendent association mechanism (see PageContext). After this, step 8 is per-
formed.
8. If the jsp:useBean action has a non-empty body, the body is processed. The
variable is initialized and available within the scope of the body. The text of
the body is treated as elsewhere. Any template text will be passed through to
Examples
In the following example, a Bean with name connection of type
com.myco.myapp.Connection is available after actions on this element, either
because it was already created and found, or because it is newly created.
In the next example, the timeout property is set to 33 if the Bean was instanti-
ated.
In the final example, the object should have been present in the session. If so,
it is given the local name wombat with WombatType. A ClassCastException
may be raised if the object is of the wrong class, and an InstantiationException
may be raised if the object is not defined.
Syntax
This action may or not have a body. If the action has no body, it is of the form:
In this case, the body will be invoked if the Bean denoted by the action is
created. Typically, the body will contain either scriptlets or jsp:setProperty tags
that will be used to modify the newly created object, but the contents of the body
are not restricted.
The <jsp:useBean> tag has the following attributes:
JSP.5.2 <jsp:setProperty>
The jsp:setProperty action sets the values of properties in a bean. The name
attribute that denotes the bean must be defined before this action appears.
There are two variants of the jsp:setProperty action. Both variants set the
values of one or more properties in the bean based on the type of the properties.
The usual bean introspection is done to discover what properties are present, and,
for each, its name, whether it is simple or indexed, its type, and the setter and get-
ter methods. Introspection also indicates if a given property type has a PropertyEd-
itor class.
Properties in a Bean can be set from one or more parameters in the request
object, from a String constant, or from a computed request-time expression.
Simple and indexed properties can be set using jsp:setProperty.
When assigning from a parameter in the request object, the conversions
described in Section JSP.1.14.2.1 are applied, using the target property to
determine the target type.
When assigning from a value given as a String constant, the conversions
described in Section JSP.1.14.2.1 are applied, using the target property to
determine the target type.
When assigning from a value given as a request-time attribute, no type
conversions are applied if a scripting expression is used, as indicated in
Section JSP.1.14.2.2. If an EL expression is used, the type conversions described
in Section JSP.2.8 are performed.
When assigning values to indexed properties the value must be an array; the
rules described in the previous paragraph apply to the actions.
A conversion failure leads to an error, whether at translation time or request-
time.
Examples
The following two actions set a value from the request parameter values.
Syntax
<jsp:setProperty name="beanName" prop_expr />
prop_expr ::=
property="*" |
property=”propertyName”|
property=”propertyName” param="parameterName"|
property=”propertyName” value=”propertyValue”
1.
See syntax for expression scriptlet <%= ... %>
JSP.5.3 <jsp:getProperty>
The <jsp:getProperty> action places the value of a bean instance property, con-
verted to a String, into the implicit out object, from which the value can be displayed
as output. The bean instance must be defined as indicated in the name attribute
before this point in the page (usually via a jsp:useBean action).
The conversion to String is done as in the println methods, i.e. the toString
method of the object is used for Object instances, and the primitive types are
converted directly.
If the object is not found, a request-time exception is raised.
Note – A consequence of the previous paragraph is that objects that are stored
in, say, the session by a front component are not automatically visible to jsp:set-
Property and jsp:getProperty actions in that page unless a jsp:useBean action, or
some other action, makes them visible.
If the JSP processor can ascertain that there is an alternate way guaranteed to
access the same object, it can use that information. For example it may use a
scripting variable, but it must guarantee that no intervening code has invalidated
the copy held by the scripting variable. The truth is always the value held by the
pageContext object.
Examples
<jsp:getProperty name=”user” property=”name” />
Syntax
<jsp:getProperty name=”name” property=”propertyName” />
name The name of the object instance from which the property is
obtained.
property Names the property to get.
JSP.5.4 <jsp:include>
A <jsp:include .../> action provides for the inclusion of static and dynamic
resources in the same context as the current page. See Table JSP.1-10 for a sum-
mary of include facilities.
Inclusion is into the current value of out. The resource is specified using a rel-
ativeURLspec that is interpreted in the context of the web application (i.e. it is
mapped).
The page attribute of both the jsp:include and the jsp:forward actions are
interpreted relative to the current JSP page, while the file attribute in an include
directive is interpreted relative to the current JSP file. See below for some
examples of combinations of this.
An included page cannot change the response status code or set headers. This
precludes invoking methods like setCookie. Attempts to invoke these methods will
be ignored. The constraint is equivalent to the one imposed on the include method
of the RequestDispatcher class.
A jsp:include action may have jsp:param subelements that can provide values
for some parameters in the request to be used for the inclusion.
Request processing resumes in the calling JSP page, once the inclusion is
completed.
The flush attribute controls flushing. If true, then, if the page output is buffered
and the flush attribute is given a true value, then the buffer is flushed prior to the
inclusion, otherwise the buffer is not flushed. The default value for the flush
attribute is false.
Examples
<jsp:include page=”/templates/copyright.html”/>
• A.jsp says <%@ include file=”dir/B.jsp”%> and dir/B.jsp says <%@ include
file=”C.jsp”%>. In this case the relative specification C.jsp resolves to dir/C.jsp.
Syntax
<jsp:include page=”urlSpec” flush="true|false"/>
and
The first syntax just does a request-time inclusion. In the second case, the
values in the param subelements are used to augment the request for the purposes
of the inclusion.
The valid attributes are:
JSP.5.5 <jsp:forward>
A <jsp:forward page=”urlSpec” /> action allows the runtime dispatch of the cur-
rent request to a static resource, a JSP page or a Java servlet class in the same con-
JavaServer Pages 2.0 Specification
<jsp:forward> 1-111
text as the current page. A jsp:forward effectively terminates the execution of the
current page. The relative urlSpec is as in Section JSP.1.2.1.
The request object will be adjusted according to the value of the page
attribute.
A jsp:forward action may have jsp:param subelements that can provide values
for some parameters in the request to be used for the forwarding.
If the page output is buffered, the buffer is cleared prior to forwarding.
If the page output is buffered and the buffer was flushed, an attempt to
forward the request will result in an IllegalStateException.
If the page output was unbuffered and anything has been written to it, an
attempt to forward the request will result in an IllegalStateException.
Examples
The following action might be used to forward to a static page based on some
dynamic condition.
Syntax
<jsp:forward page=”relativeURLspec” />
and
<jsp:forward page=”urlSpec”>
{ <jsp:param .... /> }*
</jsp:forward>
This tag allows the page author to cause the current request processing to be
affected by the specified attributes as follows:
JSP.5.6 <jsp:param>
Syntax
<jsp:param name="name" value="value" />
This action has two mandatory attributes: name and value. name indicates the
name of the parameter, and value, which may be a request-time expression,
indicates its value.
JSP.5.7 <jsp:plugin>
The plugin action enables a JSP page author to generate HTML that contains
the appropriate client browser dependent constructs (OBJECT or EMBED) that will
result in the download of the Java Plugin software (if required) and subsequent exe-
cution of the Applet or JavaBeans component specified therein.
The <jsp:plugin> tag is replaced by either an <object> or <embed> tag, as
appropriate for the requesting user agent, and emitted into the output stream of the
response. The attributes of the <jsp:plugin> tag provide configuration data for the
presentation of the element, as indicated in the table below.
The <jsp:params> action containing one or more <jsp:param> actions provides
parameters to the Applet or JavaBeans component.
The <jsp:fallback> element indicates the content to be used by the client
browser if the plugin cannot be started (either because OBJECT or EMBED is not
supported by the client browser or due to some other problem). If the plugin can
start but the Applet or JavaBeans component cannot be found or started, a plugin
specific message will be presented to the user, most likely a popup window
reporting a ClassNotFoundException.
The actual plugin code need not be bundled with the JSP container and a
reference to Sun’s plugin location can be used instead, although some vendors
will choose to include the plugin for the benefit of their customers.
Examples
<jsp:plugin type=”applet” code=”Molecule.class” codebase=”/html” >
<jsp:params>
<jsp:param
name=”molecule”
value=”molecules/benzene.mol”/>
</jsp:params>
<jsp:fallback>
<p> unable to start plugin </p>
</jsp:fallback>
</jsp:plugin>
Syntax
<jsp:plugin type="bean|applet"
code="objectCode"
codebase="objectCodebase"
{ align="alignment" }
{ archive="archiveList" }
{ height="height" }
{ hspace="hspace" }
{ jreversion="jreversion" }
{ name="componentName" }
{ vspace="vspace" }
{ title=”title” }
{ width="width" }
{ nspluginurl="url" }
{ iepluginurl="url" }
{ mayscript=’true|false’ }>
{ <jsp:params>
{ <jsp:param name="paramName" value=”paramValue" /> }+
</jsp:params> }
JSP.5.8 <jsp:params>
The jsp:params action is part of the jsp:plugin action and can only occur as a
direct child of a <jsp:plugin> action. Using the jsp:params element in any other con-
text shall result in a translation-time error.
The semantics and syntax of jsp:params are described in Section JSP.5.7.
JSP.5.9 <jsp:fallback>
The jsp:fallback action is part of the jsp:plugin action and can only occur as a
direct child of a <jsp:plugin> element. Using the jsp:fallback element in any other
context shall result in a translation-time error.
The semantics and syntax of jsp:fallback are described in Section JSP.5.7.
JSP.5.10 <jsp:attribute>
The <jsp:attribute> standard action has two uses. It allows the page author to
define the value of an action attribute in the body of an XML element instead of in
the value of an XML attribute. It also allows the page author to specify the
attributes of the element being output, when used inside a <jsp:element> action.
The action must only appear as a subelement of a standard or custom action. An
attempt to use it otherwise must result in a translation error. For example, it cannot
be used to specify the value of an attribute for XML elements that are template
text. For custom action invocations, JSP containers must support the use of
<jsp:attribute> for both Classic and Simple Tag Handlers.
The behavior of the <jsp:attribute> standard action varies depending on the
type of attribute being specified, as follows:
• If the custom action accepts dynamic attributes (Section JSP.7.1.8), and the
name of the attribute is not one explicitly indicated for the tag, then the con-
tainer will evaluate the body of <jsp:attribute> and assign the computed value
to the attribute using the dynamic attribute machinery. Since the type of the at-
tribute is unknown and the body of <jsp:attribute> evaluates to a String, the
container must pass in an instance of String.
• For standard or custom action attributes that accept a request-time expression
value, the Container must evaluate the body of the <jsp:attribute> action and
use the result of this evaluation as the value of the attribute. The body of the
attribute action can be any JSP content in this case. If the type of the attribute
is not String, the standard type conversion rules are applied, as per
Section JSP.1.14.2.1, “Conversions from String values”.
• For standard or custom action attributes that do not accept a request-time ex-
pression value, the Container must use the body of the <jsp:attribute> action as
the value of the attribute. A translation error must result if the body of the
<jsp:attribute> action contains anything but template text.
<mytag:highlight>
<jsp:attribute name=”text”>
Inline definition.
</jsp:attribute>
</mytag:highlight>
<jsp:element name=”firstname”>
<jsp:attribute name=”name”>Susan</jsp:attribute>
</jsp:element>
<firstname name=”Susan”/>
See Section JSP.1.3.10, “JSP Syntax Grammar” for the formal syntax
definition of the <jsp:attribute> standard action.
JSP.5.11 <jsp:body>
JSP.5.12 <jsp:invoke>
The <jsp:invoke> standard action can only be used in tag files (see
Chapter JSP.8, “Tag Files”), and must result in a translation error if used in a JSP.
It takes the name of an attribute that is a fragment, and invokes the fragment,
sending the output of the result to the JspWriter, or to a scoped attribute that can be
examined and manipulated. If the fragment identified by the given name is null,
<jsp:invoke> will behave as though a fragment was passed in that produces no
output.
<jsp:invoke fragment=”frag1”/>
fragment to the provided Writer. The Reader must also be resettable. That is, if its
reset method is called, the result of the invoked fragment must be able to be read
again without re-executing the fragment.
An optional scope attribute indicates the scope of the resulting scoped
variable.
The following is an example of using var or varReader and the scope attribute:
JSP.5.13 <jsp:doBody>
The <jsp:doBody> standard action can only be used in tag files (see
Chapter JSP.8, “Tag Files”), and must result in a translation error if used in a JSP.
It invokes the body of the tag, sending the output of the result to the JspWriter, or
to a scoped attribute that can be examined and manipulated.
The <jsp:doBody> standard action behaves exactly like <jsp:invoke>, except
that it operates on the body of the tag instead of on a specific fragment passed as
an attribute. Because it always operates on the body of the tag, there is no name
attribute for this standard action. The var, varReader, and scope attributes are all
supported with the same semantics as for <jsp:invoke>. Fragments are provided
access to variables the same way for <jsp:doBody> as they are for <jsp:invoke>. If
no body was passed to the tag, <jsp:doBody> will behave as though a body was
passed in that produces no output.
The body of a tag is passed to the simple tag handler as a JspFragment object.
A translation error shall result if the <jsp:doBody> action contains a non-
empty body.
See Section JSP.1.3.10, “JSP Syntax Grammar” for the formal syntax
definition of the <jsp:doBody> standard action.
The attributes are:
JSP.5.14 <jsp:element>
The jsp:element action is used to dynamically define the value of the tag of an
XML element. This action can be used in JSP pages, tag files and JSP documents.
JavaServer Pages 2.0 Specification
<jsp:element> 1-123
This action has an optional body; the body can use the jsp:attribute and jsp:body
actions.
A jsp:element action has one mandatory attribute, name, of type String. The
value of the attribute is used as that of the tag of the element generated.
Examples
The following example generates an XML element whose name depends on
the result of an EL expression, content.headerName. The element has an
attribute, lang, and the value of the attribute is that of the expression con-
tent.lang. The body of the element is the value of the expression content.body.
<jsp:element
name=”${content.headerName}”
xmlns:jsp=”http://java.sun.com/JSP/Page”>
<jsp:attribute name=”lang”>${content.lang}</jsp:attribute>
<jsp:body>${content.body}</jsp:body>
</jsp:element>
The next example fragment shows that jsp:element needs no children. The
example generates an empty element with name that of the value of the
expression myName.
<jsp:element name=”${myName}”/>
Syntax
The jsp:element action may have a body. Two forms are valid, depending on
whether the element is to have attributes or not. In the first form, no attributes are
present:
<jsp:element name="name">
optional body
</jsp:element>
In the second form, zero or more attributes are requested, using jsp:attribute
and jsp:body, as appropriate.
<jsp:element name="name">
jsp:attribute*
jsp:body?
</jsp:element>
The one valid, mandatory, attribute of jsp:element is its name. Unlike other
standard actions, the value of the name attribute must be given as an XML-style
attribute and cannot be specified using <jsp:attribute> This is because
<jsp:attribute> has a special meaning when used in the body of <jsp:element>. See
Section JSP.5.10 for more details..
JSP.5.15 <jsp:text>
A jsp:text action can be used to enclose template data in a JSP page, a JSP doc-
ument, or a tag file. A jsp:text action has no attributes and can appear anywhere that
template data can. Its syntax is:
Examples
The following example is a fragment that could be in both a JSP page or a JSP
document.
<jsp:text>
This is some content
</jsp:text>
Expressions may appear within jsp:text, as in the next example, where the
expression foo.content is evaluated and the result is inserted.
<jsp:text>
This is some content: ${foo.content}
</jsp:text>
No subelements may appear within jsp:text; for example the following frag-
<jsp:text>
This is some content: <jsp:text>foo</jsp:text>
</jsp:text>
<jsp:text>
This is some content: ${foo.content > 3}
</jsp:text>
The same example can be made legal, with no semantic changes, by using gt
instead of > in the expression; i.e. ${foo.content gt 3}.
In an JSP document, CDATA sections can also be used to quote,
uninterpreted, content, as in the following example:
<jsp:text>
<![CDATA[<mumble></foobar>]]>
</jsp:text>
Syntax
The jsp:text action has no attributes. The action may have a body. The body
may not have nested actions nor scripting elements. The body may have EL
expressions. The syntax is of the form:
<jsp:text>
optional body
</jsp:text>
JSP.5.16 <jsp:output>
The jsp:output action can only be used in JSP documents and in tag files in
XML syntax, and a translation error must result if used in a standard syntax JSP or
tag file. This action is used to modify some properties of the output of a JSP docu-
ment or a tag file. In JSP 2.0 there are four properties that can be specified, all of
which affect the output of the XML prolog.
If a doctype-public property does not appear, then the format of the generated
DOCTYPE is:
Examples
The following JSP document (with an extension of .jspx or with <is-xml> set
to true in the JSP configuration):
The following JSP document is like the previous one, except that the XML
declaration is omited. A typical use would be where the XML fragment is to
be included within another document.
The following JSP document is equivalent but uses jsp:root instead of jsp:out-
put.
The following JSP document omits the doctype-public and explicitly omits the
XML declaration:
Syntax
The jsp:output action cannot have a body. The <jsp:output> action has the
following syntax:
Chapter JSP.6 defines several other standard actions that are either convenient or
needed to describe JSP pages with an XML document, some of which are available
in all JSP pages. They are:
This chapter introduces two concepts related to XML and JSP: JSP docu-
ments and XML views. This chapter provides a brief overview of the two concepts
and their relationship and also provides the details of JSP documents. The details of
the XML view of a JSP document are described in Chapter JSP.10.
A JSP document is a JSP page written using XML syntax. JSP documents
need to be described as such, either implicitly or explicitly, to the JSP container,
which will then process them as XML documents, checking for well-formedness
and applying requests like entity declarations, if present. JSP documents are used
to generate dynamic content using the standard JSP semantics.
Here is a simple JSP document:
<table>
<c:forEach
xmlns:c="http://java.sun.com/jsp/jstl/core"
var="counter" begin="1" end="3">
<row>${counter}</row>
</c:forEach>
</table>
• JSP documents can be passed directly to the JSP container; this is becoming
more important as more and more content is authored as XML, be it in an
XML-based languages like XHTML or SVG, or for the exchange of docu-
ments in applications like Web Services. The generated content may be sent
directly to a client, or it may be part of some XML processing pipeline.
• JSP documents can be manipulated by XML-aware tools.
• A JSP document can be generated from a textual representation by applying
an XML transformation, like XSLT.
• A JSP document can be generated automatically, say by serializing some ob-
jects
Tag files can also be authored using XML syntax. The rules are very similar to
that of JSP documents; see Section JSP.8.6 for more details.
The XML view of a JSP page is an XML document that is derived from the
JSP page following a mapping defined later in this chapter.. The XML view of a
JSP page is intended to be used for validating the JSP page against some
description of the set of valid pages. Validation of the JSP page is supported in the
JSP 2.0 specification through a TagLibraryValidator class associated with a tag
library. The validator class acts on a PageData object that represents the XML
view of the JSP page (see, for example, Section JSP.7.4.1.2)
Figure JSP.6-1 below depicts the relationship between the concepts of JSP
pages, JSP documents and XML views. Two phases are involved: the Translation
phase, where JSP pages, in either syntax, are exposed to Tag Library Validators,
via their XML view, and the Request Processing phase, where requests are
processed to produce responses.
JSP Pages
TRANSLATION PHASE
XML
Syntax Request
JSP
Implementation Response
Class
REQUEST PROCESSING
PHASE
Figure JSP.6-1 Relationship between JSP Pages and XML views of JSP pages.
JSP documents are used by JSP page authors. They can be authored directly,
using a text editor, through an XML editing tool, or through a JSP page authoring
tool that is aware of the XML syntax. Any JSP page author that is generating
XML content should consider the use of JSP documents. In contrast, the XML
view of a JSP page is a concept internal to the JSP container and is of interest only
to Tag Library Authors and to implementors of JSP containers.
• If this web application is using a version 2.4 web.xml, and if the extension is
.jspx, then the file is a JSP document. Otherwise,
• If the file is explicitly or implicitly identified as a JSP page and the top element
is a jsp:root element then the file is identified as a JSP document. This behavior
provides backwards compatibility with JSP 1.2.
<jsp:text><![CDATA[<a href="]]></jsp:text><jsp:expression>url</jsp:expres-
sion><jsp:text><![CDATA[">]]></jsp:text>
In the JSP document element <a href="%= url %">, "%= url %" does not
represent a request-time attribute value. That syntax only applies for custom
action elements. This is in contrast to <a href="${url}">, where "${url}" represents
an EL expression in both JSP pages and JSP documents.
The JSP processing step for a JSP document is as for any other JSP page
except that namespaces are used to identify standard actions and custom action
tag libraries and that run time expressions in attributes use the slightly different
syntax. Note that all the JSP elements that are described in this chapter are valid in
all JSP pages, be they identified as JSP documents or not. This is a backward
compatible change from the behavior in JSP 1.2 to enable gradual introduction of
XML syntax in existing JSP pages.
To clearly explain the processing of whitespace, we follow the structure of the
XSLT specification. The first step in processing a JSP document is to identify the
nodes of the document. Then, all textual nodes that have only white space are
dropped from the document; the only exception are nodes in a jsp:text element,
which are kept verbatim. The resulting nodes are interpreted as described in the
following sections. Template data is either passed directly to the response or it is
mediated through (standard or custom) actions.
Following the XML specification (and the XSLT specification), whitespace
characters are #x20, #x9, #xD, or #xA.
The container will add, in some conditions, an XML declaration to the output;
the rules for this depend on the use of jsp:root and jsp:output; see
Section JSP.6.3.3.
Examples
The following example generates a sequence of two XML documents. No
XML declaration is generated.
Syntax
The root element has one mandatory attribute, the version of the JSP specifi-
cation the page is using. No other attributes are defined in this element.
The one valid, mandatory, attribute of jsp:root is the version of the JSP
specification used:
attributes and its body is the declaration itself. The interpretation of a jsp:declara-
tion element is as in Section JSP.1.12.1. Its syntax is:
For example, if the variable i has the value 3, and the JSP document is of the
form. :
<jsp:element
name=”${content.headerName}”
xmlns:jsp=”http://java.sun.com/JSP/Page”>
<jsp:attribute name=”lang”>${content.lang}</jsp:attribute>
<jsp:body>${content.body}</jsp:body>
</jsp:element>
templates where EL expressions are used as the values of the body or of attributes.
For instance, the next example uses the expression table.indent as the value of an
attribute, and the expression table.value as that for the body of an element:
<table indent="${table.indent}">
<row>${table.value}</row>
</table>
<table size="${3}">
<c:forEach
xmlns:c="http://java.sun.com/jsp/jstl/core"
var="counter" begin="1" end="${3}">
<row>${counter}</row>
</c:forEach>
</table>
Some comments:
• The XML template elements are <table> and <row>. The custom action ele-
ment is <c:forEach>
• The JSP standard tag library is introduced through the use of its URI
namespace and the specific prefix used, c in this case, is irrelevant. The prefix
is introduced in a non-root element, and the top element of the document is
still <table>.
• The expression ${counter} is used within the <row> template element.
• The expression ${3} (3 would have been equally good, but an expression is
used for expository reasons) is used within the value of an attribute in both the
XML template element <table> and in the custom action element
<c:forEach>.
• The JSP document does not have an xml declaration - we are assuming the en-
coding of the file did not require it, e.g. it used UTF-8, - but the output will in-
clude an xml declaration due to the defaulting rules and to the absence of
jsp:output element directing the container to do otherwise.
The JSP document above does not generate an XML document that uses
namespaces, but the next example does.
<table
xmlns="http://table.com/Table1"
size="${3}">
<c:forEach
xmlns:c="http://java.sun.com/jsp/jstl/core"
var="counter" begin="1" end="${3}">
<row>${counter}</row>
</c:forEach>
</table>
This example is essentially the same as the one above, except that a default
namespace is introduced in the top element The namespace applies to the unquali-
fied elements: <table> and <row>. Also note that if the default namespace were to
correspond to a custom action, then the elements so effected would be interpreted as
invocations on custom actions or tags.
Although the JSP container understands that this document is a namespace-
aware document. the JSP 2.0 container does not really understand that the
generated content is a well-formed XML document and, as the next example
shows, a JSP document can generate other types of content.
<jsp:root
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:jsp="http://java.sun.com/JSP/Page"
version="2.0">
<c:forEach
var="counter" begin="1" end="${3}">
<jsp:text>${counter}</jsp:text>
</c:forEach>
</jsp:root>
This example just generates 123. There is no xml declaration generated because
there is no <jsp:output> element to modify the default rule for when a JSP docu-
ment has <jsp:root>. No additional whitespace is introduced because there is none
within the <jsp:text> element.
The previous example used elements in the JSP namespace. That example
used the jsp prefix, but, unlike with JSP pages in JSP syntax, the name of the
prefix is irrelevant (although highly convenient) in JSP documents: the JSP URI is
the only important indicative and the corrent URI should be used, and introduced
via a namespace attribute.
For example, the same output would be generated with the following modifica-
tion of the previous example:
<wombat:root
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:wombat="http://java.sun.com/JSP/Page"
version="2.0">
<c:forEach
var="counter" begin="1" end="${3}">
<wombat:text>${counter}</wombat:text>
</c:forEach>
</wombat:root>
On the other hand, although the following example uses the jsp prefix the URI
used in the namespace attribute is not the JSP URI and the JSP document will
generate as output an XML document with root <jsp:root> using the URI "http://
johnsonshippingproducts.com".
<jsp:root
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:jsp="http://johnsonshippingproducts.com"
version="2.0">
<c:forEach
var="counter" begin="1" end="${3}">
<jsp:text>${counter}</jsp:text>
</c:forEach>
</jsp:root>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:u="urn:jsptagdir:/WEB-INF/tags/mylib/"
xmlns:data="http://acme.com/functions">
<c:set var="title" value="Best Movies" />
<u:headInfo title="${title}"/>
<body>
<h1>${title}</h1>
<h2>List of Best Movies</h2>
<ul>
<c:forEach var="m" varStatus="s" items="data:movieItems()">
<li><a href="#EL${s.index}">${s.index}</a>${m.title}</li>
</c:forEach>
</ul>
</body>
</html>
For convenience we use the <c:set> JSTL action, which defines variables and
associates values with them. This allows grouping in a single place of definitions
used elsewhere.
The action <u:headInfo> could be implemented either through a custom
action or through a tag. For example, as a tag it could be defined by the following
code:
This section is non-normative. Two features are sketched briefly here to elicit
input that could be used on future versions of the JSP specification.
This chapter describes the tag library facility for introducing new actions into
a JSP page. The tag library facility includes portable run-time support, a validation
mechanism, and authoring tool support. Both the classic JSP 1.2 style tag extension
mechanism and the newer JSP 2.0 simple tag extension mechanism are described. In
Chapter JSP.8, “Tag Files”, a mechanism for authoring tag extensions using only
JSP syntax is described. This brings the power of tag extensions to page authors that
may not know the Java programming language.
This chapter also provides an overview of the tag library concept. It describes
the Tag Library Descriptor, and the taglib directive. A detailed description of the
APIs involved follows in Chapter JSP.13.
JSP.7.1 Introduction
The semantics of a specific custom action in a tag library is described via a tag
handler class which is usually instantiated at runtime by the JSP page implementa-
tion class. When the tag library is well known to the JSP container
(Section JSP.7.3.9), the Container can use alternative implementations as long as the
semantics are preserved.
Tag libraries are portable: they can be used in any legal JSP page regardless of
the scripting language used in that page.
The tag extension mechanism includes information to:
A Tag Library is described via the Tag Library Descriptor ( TLD), an XML
document that is described below.
JSP.7.1.1 Goals
The tag extension mechanism described in this chapter addresses the following
goals. It is designed to be:
• Portable - An action described in a tag library must be usable in any JSP con-
tainer.
• Simple - Unsophisticated users must be able to understand and use this mech-
anism. Vendors of JSP functionality must find it easy to make it available to
users as actions.
• Expressive - The mechanism must support a wide range of actions, including
nested actions, scripting elements inside action bodies, and creation, use, and
updating of scripting variables.
• Usable from different scripting languages - Although the JSP specification
currently only defines the semantics for scripts in the Java programming lan-
guage, we want to leave open the possibility of other scripting languages.
• Built upon existing concepts and machinery - We do not want to reinvent what
exists elsewhere. Also, we want to avoid future conflicts whenever we can pre-
dict them.
JSP.7.1.2 Overview
The processing of a JSP page conceptually follows these steps:
Parsing
JSP pages can be authored using two different syntaxes: a JSP syntax and an
XML syntax. The semantics and validation of a JSP syntax page is described with
reference to the semantics and validation of an equivalent document in the XML
syntax.
The first step is to parse the JSP page. The page that is parsed is as expanded
by the processing of include directives. Information in the TLD is used in this
step, including the identification of custom tags, so there is some processing of the
taglib directives in the JSP page.
Validation
The tag libraries in the XML document are processed in the order in which
they appear in the page.
Each library is checked for a validator class. If one is present, the whole
document is made available to its validate method as a PageData object. As of JSP
2.0, the Container must provide a jsp:id attribute. This information can be used to
provide location information on errors.
Each custom tag in the library is checked for a TagExtraInfo class. If one is
present, its validate method is invoked. The default implementation of validate is
to call isValid. See the APIs for more details.
Translation
Finally, the XML document is processed to create a JSP page implementation
class. This process may involve creating scripting variables. Each custom action
will provide information about variables, either statically in the TLD, or more
flexibly by using the getVariableInfo method of a TagExtraInfo class.
Execution
Once a JSP page implementation class has been associated with a JSP page,
the class will be treated as any other servlet class: Requests will be directed to
instances of the class. At run-time, tag handler instances will be created and
methods will be invoked in them.
• The Tag interface defines the basic methods needed in all tag handlers. These
methods include setter methods to initialize a tag handler with context data and
attribute values of the action, and the doStartTag and doEndTag methods.
• The IterationTag interface is an extension to Tag that provides the additional
method, doAfterBody, invoked for the reevaluation of the body of the tag.
• The BodyTag interface is an extension of IterationTag with two new methods
for when the tag handler wants to manipulate the tag body: setBodyContent
passes a buffer, the BodyContent object, and doInitBody provides an opportuni-
ty to process the buffer before the first evaluation of the body into the buffer.
The use of interfaces simplifies making an existing Java object a tag handler.
There are also two support classes that can be used as base classes: TagSupport
and BodyTagSupport.
JSP 1.2 introduced a new interface designed to help maintain data integrity
and resource management in the presence of exceptions. The TryCatchFinally
interface is a “mix-in” interface that can be added to a class implementing any of
Tag, IterationTag, or BodyTag.
invoked when the start tag is encountered. It can access the attributes of the tag
and information about the state of the JSP page. The information is passed to the
Tag object through setter method calls, prior to the call to doStartTag.
Since simple actions with empty tag bodies are common, the Tag Library
Descriptor can be used to indicate that the tag is always intended to be empty. This
indication leads to better error checking at translation time, and to better code
quality in the JSP page implementation class.
JSP.7.1.4.3 Conditionals
In some cases, a body needs to be invoked only when some (possibly complex)
condition happens. Again, this type of action is supported by the basic Tag interface
through the use of return values in the doStartTag method.
JSP.7.1.4.4 Iterations
For iteration the IterationTag interface is needed. The doAfterBody method is
invoked to determine whether to reevaluate the body or not.
of a server-side object, while another action may use that object elsewhere in the
page. These actions may cooperate explicitly, via scoped variables: one action cre-
ates an object and gives it a name; the other refers to the object through the name.
Two actions can also cooperate implicitly. A flexible and convenient
mechanism for action cooperation uses the nested structure of the actions to
describe scoping. This is supported in the specification by providing each tag
handler with its parent tag handler (if any) through the setParent method. The fin-
dAncestorWithClass static method in TagSupport can then be used to locate a tag
handler, and, once located, to perform valid operations on the tag handler.
JSP.7.1.7.3 Conditionals
All conditional logic is handled in the doTag method. If the body is not to be
invoked, the tag library developer simply does not call invoke on the JspFragment
object passed in via setJspBody.
JSP.7.1.7.4 Iterations
All iteration logic is handled in the doTag method. The tag library developer
simply calls invoke on the JspFragment object passed in via setJspBody as many
times as needed.
conventions described in the Servlet 2.4 specification apply, including the conven-
tions for dependencies on extensions.
Packaged tag libraries must have at least one tag library descriptor file. The
JSP 1.1 specification allowed only a single TLD, in META-INF/taglib.tld, but as of
JSP 1.2 multiple tag libraries are allowed. See Section JSP.7.3.1 for how TLDs are
identified.
Both Classic and Simple Tag Handlers (implemented either in Java or as tag
files) can be packaged together.
The Tag Library Descriptor (TLD) is an XML document that describes a tag
library. The TLD for a tag library is used by a JSP container to interpret pages that
include taglib directives referring to that tag library. The TLD is also used by JSP
page authoring tools that will generate JSP pages that use a library, and by authors
who do the same manually.
The TLD includes documentation on the library as a whole and on its
individual tags, version information on the JSP container and on the tag library,
and information on each of the actions defined in the tag library.
The TLD may name a TagLibraryValidator class that can validate that a JSP
page conforms to a set of constraints expected by the tag library.
Each action in the library is described by giving its name, the class of its tag
handler, information on any scripting variables created by the action, and
information on attributes of the action. Scripting variable information can be
given directly in the TLD or through a TagExtraInfo class. For each valid attribute
there is an indication about whether it is mandatory, whether it can accept request-
time expressions, and additional information.
A TLD file is useful for providing information on a tag library. It can be read
by tools without instantiating objects or loader classes. Our approach conforms to
the conventions used in other J2EE technologies.
As of JSP 2.0, the format for the Tag Library Descriptor is represented in
XML Schema. This allows for a more extensible TLD that can be used as a true
single-source document.
directive. More details about identifying this implicit Tag Library Descriptor can
be found in Chapter JSP.8, “Tag Files”.
• The container searches for all files with a .tld extension under /WEB-INF or a
subdirectory, and inside JAR files that are in /WEB-INF/lib. When examining a
JAR file, only resources under /META-INF or a subdirectory are considered.
The order in which these files are searched for is implementation-specific and
should not be relied on by web applications.
• Each TLD file is examined. If it has a <uri> element, then a new <taglib> ele-
ment is created, with a <taglib-uri> subelement whose value is that of the <uri>
element, and with a <taglib-location> subelement that refers to the TLD file.
• If the created <taglib> element has a different <taglib-uri> to any in the taglib
map, it is added.
<taglib>
<taglib-uri>/myPRlibrary</taglib-uri>
<taglib-location>/WEB-INF/tlds/PRlibrary_1_4.tld</taglib-location>
</taglib>
Finally, the fallback rule allows a taglib directive to refer directly to the TLD.
This arrangement is very convenient for quick development at the expense of less
flexibility and accountability. For example, in the case above, it enables:
TLD map. The assembler may create taglib entries in web.xml for each of the
libraries that are to be used.
Part of the assembly (and later the deployment) may create and/or change
information that customizes a tag library; see Section JSP.7.5.3.
There are efforts under way in the JCP (Java Community Process) to define
standard extensions for enhanced tool support for JSP page authoring. Such
standard extensions should be used where appropriate.
JSP.7.3.10.1 Example
In the following non-normative example, a fictitious company called ACME
has decided to enhance the page author’s experience by defining a set of Tag and
Tag Library Extension elements that cause sounds to be played when inserting
tags in a document.
In this hypothetical example, ACME has published an XML Schema at http://
www.acme.com/acme.xsd that defines the extensions, and has provided plug-ins
for various JSP-capable IDEs to recognize these extension elements.
The following example tag library uses ACME’s extensions to provide helpful
voice annotations that describe how to use each tag in the tag library. Relevant
parts highlighted in bold:
<taglib xmlns=”http://java.sun.com/xml/ns/j2ee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:acme=”http://acme.com/”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd
http://acme.com/ http://acme.com/acme.xsd”
version=”2.0”>
<description>
Simple Math Tag Library.
Contains ACME sound extensions with helpful voice annotations
that describe how to use the tags in this library.
</description>
<tlib-version>1.0</tlib-version>
<short-name>math</short-name>
<tag>
<xsd:schema
targetNamespace=”http://acme.com/”
xmlns:j2ee=”http://java.sun.com/xml/ns/j2ee”
xmlns:acme=”http://acme.com/”
xmlns:xsd=”http://www.w3.org/2001/XMLSchema”
xmlns:xml=”http://www.w3.org/XML/1998/namespace”
elementFormDefault=”qualified”
attributeFormDefault=”unqualified”
version=”1.0”>
<xsd:annotation>
<xsd:documentation>
This an XML Schema for sample Acme taglib extensibility
elements, used to test TLD extensibility.
</xsd:documentation>
</xsd:annotation>
<xsd:import namespace=”http://java.sun.com/xml/ns/j2ee”
schemaLocation=”../web-jsptaglibrary_2_0.xsd” />
<xsd:complexType name=”acme-soundsType”>
<xsd:annotation>
<xsd:documentation>
Extension for sounds associated with a tag
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base=”j2ee:extensibleType”>
<xsd:sequence>
<xsd:element name=”version” type=”xsd:string”/>
<xsd:element name=”tag-sound” type=”xsd:string”
minOccurs=”0” maxOccurs=”unbounded”/>
<xsd:element name=”attribute-sound”
minOccurs=”0” maxOccurs=”unbounded”>
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base=”xsd:string”>
<xsd:attribute name=”name” use=”required”
type=”xsd:string” />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name=”import-sound” type=”xsd:string”
minOccurs=”0” maxOccurs=”unbounded”/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
JSP.7.4 Validation
There are a number of reasons why the structure of a JSP page should conform
to some validation rules:
ception can be thrown. If uncaught, this object will invoke the errorpage mechanism
of the JSP specification.
This chapter describes the details of tag files, a JSP 2.0 facility that allows
page authors to author tag extensions using only JSP syntax. In the past, the ability
to encapsulate presentation logic into reusable, full-featured tag libraries was only
available to developers that had a reasonable amount of Java experience. Tag files
bring the power of reuse to the basic page author, who are not required to know
Java. When used together with JSP Fragments and Simple Tag Handlers, these con-
cepts have the ability to simplify JSP development substantially, even for developers
who do know Java.
JSP.8.1 Overview
As of JSP version 2.0, the JSP Compiler is required to recognize tag files. A
tag file is a source file that provides a way for a page author to abstract a segment
of JSP code and make it reusable via a custom action.
Tag files allow a JSP page author to create tag libraries using JSP syntax. This
means that page authors no longer need to know Java or ask someone who knows
Java to write a tag extension. Even for page authors or tag library developers who
know Java, writing tag files is more convenient when developing tags that
primarily output template text.
The required file extension for a tag file are .tag or .tagx. As is the case with
JSP files, the actual tag may be composed of a top file that includes other files that
contain either a complete tag or a segment of a tag file. Just as the recommended
extension for a segment of a JSP file is .jspf, the recommended extension for a
segment of a tag file is .tagf.
The syntax of a tag file is similar to that of a JSP page, with the following
exceptions:
• Directives - Some directives are not available or have limited availability, and
some tag file specific directives are available. See Section JSP.8.5, “Tag File
Directives” for a discussion on tag file directives.
• The <jsp:invoke> and <jsp:doBody> standard actions can only be used in Tag
Files.
The EBNF grammar in Section JSP.1.3.10, “JSP Syntax Grammar” describes
the syntax of tag files. The root production for a tag files is JSPTagDef.
See Section JSP.8.6 for details on tag files in XML syntax.
For each tag file in the web application, a tag handler is made available to JSP
pages and other tag files. The specifics of how this is done are left up to the Con-
tainer implementation. For example, some Containers may choose to compile tag
files into Java tag handlers, whereas others may decide to interpret the tag handlers.
However the Container chooses to prepare the tag handler, the following
conditions must hold true for all tag handlers defined as tag files:
• The tag file implementation must keep a copy of the JspContext instance
passed to it by the invoking page via the setJspContext method. This is called
the Invoking JSP Context.
• The tag file implementation must create and maintain a second instance of
JspContext called a JSP Context Wrapper. If the Invoking JSP Context is an
instance of PageContext, the JSP Context Wrapper must also be an instance of
PageContext. This wrapper must be returned when getJspContext() is called.
• For each invocation to the tag, the JSP Context Wrapper must present a clean
page scope containing no initial elements. All scopes other than the page
scope must be identical to those in the Invoking JSP Context and must be
modified accordingly when updates are made to those scopes in the JSP Con-
text Wrapper. Any modifications to the page scope, however, must not affect
the Invoking JSP Context.
• For each attribute declared and specified, a page-scoped variable must be cre-
ated in the page scope of the JSP Context Wrapper. The name of the variable
must be the same as the declared attribute name. The value of the variable
must be the value of the attribute passed in during invocation. For each at-
tribute declared as optional and not specified, no page-scoped variable is cre-
ated. If the tag accepts dynamic attributes, then the names and values of those
dynamic attributes must be exposed to the tag file as specified in Table JSP.8-
2.
• For all intents and purposes other than for synchronizing the AT_BEGIN,
NESTED, and AT_END scripting variables, the effective JspContext for the tag
file is the JSP Context Wrapper. For example, the jspContext scripting variable
must point to the JSP Context Wrapper instead of the invoking JSP Context.
• The tag handler must behave as though a tag library descriptor entry was de-
fined for it, in accordance with the tag, attribute, and variable directives that
appear in the tag file translation unit.
It is legal for a tag file to forward to a page via the <jsp:forward> standard
action. Just as for JSP pages, the forward is handled through the request
dispatcher. Upon return from the RequestDispatcher.forward method, the
generated tag handler must stop processing of the tag file and throw javax.serv-
let.jsp.SkipPageException. Similarly, if a tag file invokes a Classic Tag Handler
which returns SKIP_PAGE from the doEndTag method, or if it invokes a Simple
Tag Handler which throws SkipPageException in the doTag method, the generated
tag handler must terminate and SkipPageException must be thrown. In either of
these two cases, the doCatch and doFinally methods must be called on enclosing
tags that implement the TryCatchFinally interface before returning. The doEndTag
methods of enclosing classic tags must not be called.
Care should be taken when invoking a classic tag handler from a tag file. In
general, SimpleTag Extensions can be used in environments other than servlet
environments. However, because the Tag interface relies on PageContext, which in
turn assumes a servlet environment, using classic tag handlers indirectly binds the
use of the tag file to servlet environments. Nonetheless, the JSP container must
allow such an invocation to occur. When a tag file attempts to invoke a classic tag
handler (i.e. one that implements the Tag interface), it must cast the JspContext
passed to the SimpleTag into a PageContext. In the event that the class cast fails,
the invocation of the classic tag fails, and a JspException must be thrown.
One of the goals of tag files as a technology is to make it as easy to write a tag
handler as it is to write a JSP. Traditionally, writing tag handlers has been a
tedious task, with a lot of time spent compiling and packaging the tag handlers
and writing a TLD to provide information to tools and page authors about the
custom actions. The rules for packaging tag files are designed to make it very
simple and fast to write simple tags, while still providing as much power and
flexibility as classic tag handlers have.
that <tag> and <tag-file> share a namespace, a tag library is considered invalid and
must be rejected by the container if a <tag-file> element has a <name> subelement
with the same content as a <name> subelement in a <tag> element. Any attempt to
use an invalid tag library must trigger a translation error.
/WEB-INF/tags/
/WEB-INF/tags/a.tag
/WEB-INF/tags/b.tag
/WEB-INF/tags/foo/
/WEB-INF/tags/foo/c.tag
/WEB-INF/tags/bar/baz/
/WEB-INF/tags/bar/baz/d.tag
The JSP container must generate an implicit tag library for each directory
under and including /WEB-INF/tags/. This tag library can be imported only via the
tagdir attribute of the taglib directive (see Section JSP.1.10.2), and has the
following hard-wired values:
• A <tag-file> element is considered to exist for each tag file in this directory,
with the following sub-elements:
■
The <name> for each is the filename of the tag file, without the .tag exten-
sion.
■
The <path> for each is the path of the tag file, relative to the root of the web
application.
For the above example, the implicit Tag Library Descriptor for the /WEB-INF/
tags/bar/baz/ directory would be:
<taglib>
<tlib-version>1.0</tlib-version>
<short-name>bar-baz</short-name>
<tag-file>
<name>d</name>
<path>/WEB-INF/tags/bar/baz/d.tag</path>
</tag-file>
</taglib>
Upon deployment, the JSP container must search for and process all tag files
appearing in these directories and subdirectories. In processing a tag file, the
container makes the custom actions defined in these tags available to JSP files.
Despite the existence of an implicit tag library, a Tag Library Descriptor in the
web application can still create additional tags from the same tag files. This is
accomplished by adding a <tag-file> element with a <path> that points to the tag
file. In this case, the value of <path> must start with /WEB-INF/tags.
This section describes the directives available within tag files, which define
Simple Tag Handlers. Table JSP.8-1 outlines which directives are available in tag
files:
The attribute/value namespace is reserved for use by this, and subsequent, JSP
specification(s).
Unrecognized attributes or values result in fatal translation errors.
Examples
<%@ tag display-name=”Addition”
body-content=”scriptless”
dynamic-attributes=”dyn”
small-icon=”/WEB-INF/sample-small.jpg”
large-icon=”/WEB-INF/sample-large.jpg”
description=”Sample usage of tag directive” %>
Syntax
<%@ tag tag_directive_attr_list %>
tag_directive_attr_list ::=
{ display-name=”display-name” }
{ body-content=”scriptless|tagdependent|empty” }
{ dynamic-attributes=”name” }
{ small-icon=”small-icon” }
{ large-icon=”large-icon” }
{ description=”description” }
{ example=”example” }
{ language=”scriptingLanguage” }
{ import=”importList” }
{ pageEncoding=”peinfo” }
{ isELIgnored=”true|false” }
pageEncoding (optional) Carries the same syntax and semantics of the pag-
eEncoding attribute in the page directive. However, there is
no corresponding global configuration element in web.xml.
The pageEncoding attribute cannot be used in tag files in
XML syntax.
isELIgnored (optional) Carries the same syntax and semantics of the isE-
LIgnored attribute of the page directive. However, there is no
corresponding global configuration element in web.xml.
Examples
<%@ attribute name=”x” required=”true” fragment=”false”
rtexprvalue=”false” type=”java.lang.Integer”
description=”The first operand” %>
Syntax
<%@ attribute attribute_directive_attr_list %>
attribute_directive_attr_list ::=
name=”attribute-name”
{ required=”true|false” }
{ fragment=”true|false” }
{ rtexprvalue=”true|false” }
{ type=”type” }
{ description=”description” }
Examples
<%@ variable name-given=”sum”
variable-class=”java.lang.Integer”
scope=”NESTED”
declare=”true”
description=”The sum of the two operands” %>
Syntax
<%@ variable variable_directive_attr_list %>
variable_directive_attr_list ::=
( name-given=”output-name”
| ( name-from-attribute=”attr-name”
alias=”local-name”
)
)
{ variable-class=”output-type” }
{ declare=”true|false” }
{ scope=”AT_BEGIN|AT_END|NESTED” }
{ description=”description” }
Tag files can be authored using the XML syntax, as described in JSP Docu-
ments, Chapter JSP.6. This section describes the few distinctions from the case of
JSP documents.
Tag files in XML syntax must have the extension .tagx. All files with
extension .tagx according to the rules in Section JSP.8.4.1 are tag files in XML
syntax. Conversely, files with extension .tag are not in XML syntax.
The jsp:root element can, but needs not, appear in tag files in XML syntax. A
jsp:root element cannot appear in a tag file in JSP syntax.
As indicated in Section JSP.5.16, “<jsp:output>”, the default for tag files, in
either syntax, is not to generate the xml declaration. The element jsp:output can be
used to change that default for tag files in XML syntax.
Finally, the tag directive in a tag file in XML syntax cannot include a pageEn-
coding attribute; the encoding is inferred using the conventions for XML
documents. Using the pageEncoding attribute shall result in a translation-time
error.
Similar to JSP pages, tag files have an equivalent XML document, the XML
view of a tag file, that is exposed to the translation phase for validation. During the
translation phase for a tag file, a tag XML view is created and passed to all TLVs
declared in all tag libraries declared in the tag file.
The XML view of a tag file is identical to the XML view of a JSP, except that
there are additional XML elements defined to handle tag file specific features. The
XML view of a tag file is obtained in the same way that the XML view of a JSP
page is obtained (see Chapter JSP.10).
Tag library developers writing tag files have access to certain implicit objects
that are always available for use within scriptlets and expressions through
scripting variables that are declared implicitly at the beginning of the tag handler
implementation. All scripting languages are required to provide access to these
objects.
Each implicit object has a class or interface type defined in a core Java
technology or Java Servlet API package, as shown in Table JSP.8-5.
Variable
Name Type Semantics & Scope
Object names with prefixes jsp, _jsp, jspx and _jspx, in any combination of
upper and lower case, are reserved by the JSP specification.
Just as is the case for all tag handlers, a tag file is able to communicate with its
calling page via variables. As mentioned earlier, in tag files, variables are declared
using the variable directive. Though the scopes of variables are similar to those in
classic tag handlers, the semantics are slightly different. The intent is to be able to
emulate IN and OUT parameters using attributes and variables, which appear as
page-scoped attributes local to the tag file, and are synchronized with the calling
page’s JspContext at various points.
The name-from-attribute and alias attributes of the variable directive can be
used to allow the caller to customize the name of the variable in the calling page
while referring to a constant name in the tag file. When using these attributes, the
name of the variable in the calling page is derived from the value of name-from-
attribute at the time the tag was called. The name of the corresponding variable in
the tag file is the value of alias.
• tag → page - For this variable, if T exists in the tag file, create/update P in the
calling page. If a T does not exist in the tag file, and P does exist in the calling
page, P is removed from the calling page’s page scope. If the declare attribute
for this variable is set to true, a corresponding scripting variable is declared in
the calling page or tag file, as with any other tag handler. If this scripting vari-
able would not be accessible in the context in which it is defined, the container
need not declare the scripting variable (for example in a scriptless body).
• save - For this variable, save the value of P, for later restoration. If P did not
exist, remember that fact.
• restore - For this variable, restore the value of P in the calling page, from the
value saved earlier. If P did not exist before, ensure it does not exist now.
All variable synchronization and restoration that occurs at the end of a tag file
must occur regardless of whether an exception is thrown inside the tag file. All
variable synchronization that occurs after the invocation of a fragment must occur
regardless of whether an exception occured while invoking the fragment.
This chapter describes the details of the Scripting Elements when the lan-
guage directive value is java.
The scripting language is based on the Java programming language (as
specified by “The Java Language Specification”), but note that there is no valid
JSP page, or a subset of a page, that is a valid Java program.
The following sections describe the details of the relationship between the
scripting declarations, scriptlets, and scripting expressions, and the Java
programming language. The description is in terms of the structure of the JSP
page implementation class. A JSP Container need not generate the JSP page
implementation class, but it must behave as if one exists.
Some details of what makes a JSP page legal are very specific to the scripting
language used in the page. This is especially complex since scriptlets are language
fragments, not complete language statements.
(2) Implicit Objects // code that defines and initializes request, response, page,
Section pageContext etc.
close of _jspService }
method
close of _jspXXX }
This section defines and initializes the implicit objects available to the JSP page.
See Section JSP.1.8.3, “Implicit Objects”.
This section provides the main mapping between a request and a response
object.
The content of code segment 2 is determined from scriptlets, expressions, and
the text body of the JSP page. The elements are processed sequentially in the
order in which they appear in the page. The translation for each one is determined
as indicated below, and its translation is inserted into this section. The translation
depends on the element type:
JSP.9.4.2 Scriptlets
A scriptlet is transformed into its code fragment.:
JSP.9.4.3 Expressions
An expression is transformed into a Java statement to insert the value of the
expression, converted to java.lang.String if needed, into the stream named by the
implicit variable out. No additional newlines or space is included.
Ignoring quotation and performance issues, this corresponds to a statement of
the form:
JSP.9.4.4 Actions
An action defining one or more objects is transformed into one or more variable
declarations for those objects, together with code that initializes the variables. Their
visibility is affected by other constructs, for example scriptlets.
The semantics of the action type determines the names of the variables
(usually the name of an id attribute, if present) and their type. The only standard
action in the JSP specification that defines objects is the jsp:useBean action. The
name of the variable introduced is the name of the id attribute and its type is the
type of the class attribute.
Note that the value of the scope attribute does not affect the visibility of the
variables within the generated program. It affects where and thus for how long
there will be additional references to the object denoted by the variable.
This chapter provides details on the XML view of a JSP page and tag files.
The XML views are used to enable validation of JSP pages and tag files..
This section describes the XML view of a JSP page or tag file: the mapping
between a JSP page, JSP document or tag file, and an XML document describing it.
• Expand all include directives into the JSP content they include. See
Section JSP.1.10.5 for the semantics of mixing XML and standard syntax con-
tent.
• Add a jsp:root element as the root element if the JSP document or tag file in
XML syntax does not have it.
• Set the value of the pageEncoding attribute of the page directive to "UTF-8".
The page directive and the pageEncoding attribute are added if they don’t ex-
ist already.
• Set the value of the contentType attribute of the page directive to the value that
the container will pass to ServletResponse.setContentType(), determined as
described in Section JSP.4.2, “Response Character Encoding”. The page di-
rective and the contentType attribute are added if they don’t exist already.
• Add the jsp:id attribute (see Section JSP.10.1.13).
JavaServer Pages 2.0 Specification 1-201
1-202 XML VIEW
• Expand all include directives into the JSP content they include. See
Section JSP.1.10.5 for the semantics of mixing XML and standard syntax con-
tent.
• Add a jsp:root element as the root, with appropriate xmlns:jsp attribute, and
convert the taglib directive into xmlns: attributes of the jsp:root element.
• Convert declarations, scriptlets, and expressions into valid XML elements as
described in Section JSP.6.3.2 and the following sections.
• Convert request-time attribute expressions as in Section JSP.10.1.11.
• Convert JSP quotations to XML quotations.
• Create jsp:text elements for all template text.
• Add the jsp:id attribute (see Section JSP.10.1.13).
Note that the XML view of a JSP page or tag file has no DOCTYPE
information; see Section JSP.10.2.
A quick overview of the transformation is shown in Table JSP.10-1:
<%@ attribute ... %> <jsp:directive.attribute ... />. Add jsp:id. [tag files only]
<%@ variable ... %> <jsp:directive.variable ... />. Add jsp:id. [tag files only]
In more detail:
The value of the pageEncoding attribute is set to "UTF-8". The value of the
contentType attribute is set to the value that the container will pass to
ServletResponse.setContentType(), determined as described in Section JSP.4.2,
“Response Character Encoding”. The page directive and both attributes are added
if they don’t exist already.
is translated into an xmlns:prefix attribute on the root of the JSP document, with
a value that depends on uriValue. If uriValue is a relative path, then the value used is
urn:jsptld:uriValue; otherwise, the uriValue is used directly.
is translated into an xmlns:prefix attribute on the root of the JSP document, with
a value of the form urn:jsptagdir:tagDirValue.
is expanded into the JSP content indicated by value. This is done to allow for
validation of the page.
JSP.10.1.7 Declarations
Declarations are translated into a jsp:declaration element. For example, the sec-
ond example from Section JSP.1.12.1:
JSP.10.1.8 Scriptlets
Scriptlets are translated into a jsp:scriptlet element. In the XML document cor-
responding to JSP pages, directives are represented using the syntax:
JSP.10.1.9 Expressions
In the XML document corresponding to JSP pages, directives are represented
using the jsp:expression element:
The value of the pageEncoding attribute is set to "UTF-8". A tag directive and
the pageEncoding attribute are added if they don’t exist already.
JSP.10.3 Examples
This section presents various examples of XML Views. The first shows a JSP
page in XML syntax that includes XML fragments. The second shows a JSP page in
JSP syntax and its mapping to XML syntax. The three following examples illustrate
the semantics of cross-syntax translation-time includes and the effect on the XML
View.
1.
Similarly, when applying an XSLT transformation to a JSP document,
XML fragments will be plainly visible, while the content of jsp:text ele-
ments will not
<?xml version="1.0"?>
<table>
<c:forEach
xmlns:c="http://java.sun.com/jsp/jstl/core"
var="counter" begin="1" end="3">
<row>${counter}</row>
</c:forEach>
</table>
<html>
<title>positiveTagLib</title>
<body>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:eg="http://java.apache.org/tomcat/examples-taglib"
xmlns:test="urn:jsptld:/tomcat/taglib"
xmlns:temp="urn:jsptld:/WEB-INF/tlds/my.tld"
version="2.0">
<jsp:text><![CDATA[<html>
<title>positiveTagLib</title>
<body>
]]></jsp:text>
<eg:test toBrowser="true" att1="Working">
<jsp:text>Positive test taglib directive</jsp:text>
</eg:test>
<jsp:text><![CDATA[
</body>
</html>
]]></jsp:text>
</jsp:root>
The resulting XML View for these two JSP documents is:
<jsp:root>
<elementA>
<tagB xmlns="http://namespace1">
<elementC />
</tagB>
</elementA>
</jsp:root>
<jsp:root xmlns:x="http://namespace2">
<elementD>
<x:tagE />
<x:tagE />
</elementD>
</jsp:root>
<jsp:root xmlns:m="http://namespace3"
xmlns:n="http://namespace6">
<tagF xmlns="http://namespace4">
<y:tagG xmlns:y="http://namespace5">
<tagH />
<y:tagL xmlns="" xmlns:y="http://namespace7">
<elementM />
<m:tagJ />
<n:tagK />
</y:tagL>
</y:tagG>
<m:tagJ />
<n:tagK />
<tagI />
</tagF>
</jsp:root>
• JSP Container
• Core API
• Tag Extension API
• Expression Language API
This chapter describes the contracts between a JSP container and a JSP page,
including the precompilation protocol and debugging support requirements.
The information in this chapter is independent of the Scripting Language used
in the JSP page. Chapter JSP.9 describes information specific to when the lan-
guage attribute of the page directive has java as its value.).
JSP page implementation classes should use the JspFactory and PageContext
classes to take advantage of platform-specific implementations.
described by the HttpServlet class. Most JSP pages use the HTTP protocol, but
other protocols are allowed by this specification.
The JSP container automatically makes a number of server-side objects
available to the JSP page implementation object . See Section JSP.1.8.3.
The involved contracts are shown in Figure JSP.11-1. We now revisit this
whole process in more detail.
The JSP container creates a JSP page implementation class for each JSP page.
The name of the JSP page implementation class is implementation dependent.
The JSP Page implementation object belongs to an implementation-dependent
named package. The package used may vary between one JSP and another, so
minimal assumptions should be made.
As of JSP 2.0, it is illegal to refer to any classes from the unnamed (a.k.a.
default) package. This may result in a translation error on some containers,
specifically those that run in a JDK 1.4 or greater environment. It is unfortunate,
but unavoidable, that this will break compatibility with some older JSP
applications. However, as of JDK 1.4, importing classes from the unnamed
package is not valid (see http://java.sun.com/j2se/1.4/compatibility.html#source
for details). Therefore, for forwards compatibility, applications must not rely on
the unnamed package. This restriction also applies for all other cases where
classes are referenced, such as when specifying the class name for a tag in a TLD.
The JSP container may create the implementation class for a JSP page, or a
superclass may be provided by the JSP page author through the use of the extends
attribute in the page directive.
The extends mechanism is available for sophisticated users. It should be used
with extreme care as it restricts decisions that a JSP container can make. It may
restrict efforts to improve performance, for example.
The JSP page implementation class will implement javax.servlet.Servlet and
requests are delivered to the class as per the rules in the Servlet 2.4 specification.
A JSP page implementation class may depend on support classes. If the JSP
page implementation class is packaged into a WAR, any dependent classes will
have to be included so it will be portable across all JSP containers.
A JSP page author writes a JSP page expecting that the client and the server
will communicate using a certain protocol. The JSP container must guarantee that
requests to and responses from the page use that protocol. Most JSP pages use
HTTP, and their implementation classes must implement the HttpJspPage
interface, which extends JspPage. If the protocol is not HTTP, then the class will
implement an interface that extends JspPage.
imports javax.servlet.*;
imports javax.servlet.http.*;
imports javax.servlet.jsp.*;
/**
* An example of a superclass for an HTTP JSP class
*/
/**
* The entry point into service.
*/
_jspService(request, response);
}
/**
* abstract method to be provided by the JSP processor in the subclass
* Must be defined in subclass.
*/
imports javax.servlet.*;
imports javax.servlet.http.*;
imports javax.servlet.jsp.*;
/**
* An example of a class generated for a JSP.
*
* The name of the class is unpredictable.
* We are assuming that this is an HTTP JSP page (like almost all are)
*/
The contract on the JSP page implementation class does not change. The JSP
container should check (usually through reflection) that the provided superclass:
Additionally, it is the responsibility of the JSP page author that the provided
superclass satisfies:
• The service method of the servlet API invokes the _jspService method.
• The init(ServletConfig) method stores the configuration, makes it available via
getServletConfig, then invokes jspInit.
A JSP container may give a fatal translation error if it detects that the provided
superclass does not satisfy these requirements, but most JSP containers will not
check them.
JSP.11.3 Buffering
The JSP container buffers data (if the jsp directive specifies it using the buffer
attribute) as it is sent from the server to the client. Headers are not sent to the client
until the first flush method is invoked. Therefore, it is possible to call methods that
modify the response header, such as setContentType, sendRedirect, or error meth-
ods, up until the flush method is executed and the headers are sent. After that point,
these methods become invalid, as per the Servlet specification.
The javax.servlet.jsp.JspWriter class buffers and sends output. The JspWriter
class is used in the _jspService method as in the following example:
import javax.servlet.jsp.JspWriter;
JSP.11.4 Precompilation
A JSP page that is using the HTTP protocol will receive HTTP requests. JSP 2.0
compliant containers must support a simple precompilation protocol, as well as
some basic reserved parameter names. Note that the precompilation protocol is
related but not the same as the notion of compiling a JSP page into a Servlet class
(Appendix JSP.A).
All JSPs pages should ignore (not depend on) any parameter that starts with
jsp_.
1. ?jsp_precompile
2. ?jsp_precompile=true
3. ?jsp_precompile=false
4. ?foobar=foobaz&jsp_precompile=true
5. ?foobar=foobaz&jsp_precompile=false
1, 2, and 4 are legal; the request will not be delivered to the page. 3 and 5 are
legal; the request will not be delivered to the page.
6. ?jsp_precompile=foo
This is illegal and will generate an HTTP error; 500 (Server error).
named JSP in the Source Debug Extension (this stratum name is reserved for use
by the JSP specification). This stratum should be specified as the default, unless
the page or tag file was generated from some other source.
The exact mechanism for causing the JSP compiler to produce source map
debugging information is currently implementation-dependent. Full runtime
support for JSR-45 (as opposed to only generating the SMAPs that are used at
runtime) will typically only be supported when the JSP container is running in a
J2SE 1.4 or greater environment.
1. Abreakpoint on a JSP line causes execution to stop before any Java code which
amounts to a translation of the JSP line is executed (for one possible exception,
see 5). Note that given the LineInfo Composition Algorithm (see JSR-45 spec-
ification), it is acceptable for the mappings to include one or more Java lines
which are never translated into executable byte code, as long as at least one of
them does.
2. It is permitted for two or more lines of JSP to include the same Java lines in
their mappings.
3. If a line of JSP has no manifestation in the Java source other than white-space
preserving source, it should not be mapped.
■
The following standard syntax JSP entities should not be mapped to gener-
ated code. These entities either have no manifestation in the generated Java
code (e.g. comments), or are not manifest in such a way that it allows the de-
bugged process to stop (e.g. the page directive import):
• JSP comments
• Directives
■
The following XML syntax JSP entities should not be mapped to generated
code. These entities frequently have no manifestation in the generated Java
code.
• <jsp:root>
• <jsp:output>
4. Declarations and scriptlets (standard or XML JSP). Lines in these constructs
In this example, given that <h1> has its own call to write(), it makes sense to
map 101 to 201, 202 etc.
In this second example, given that <h1> is output using the same call to write()
that was used for line 100, mapping 101 to 202, 203 etc. may result in more
intuitive behavior of the debugger.
For scriptlets that contain more than one line, there should be a one-to-one
mapping from JSP to Java lines, and the mapping should start at the first Java
code that is not whitespace or comments. Therefore, a line that contains only
the open scriptlet delimeter is not mapped.
This section describes the basic contract between a JSP Page implementation
object and its container. The main contract is defined by the classes JspPage and
HttpJspPage. The JspFactory class describes the mechanism to portably instantiate
all needed runtime objects, and JspEngineInfo provides basic information on the cur-
rent JSP container.
None of the classes described here are intended to be used by JSP page
authors; an example of how these classes may be used is included elsewhere in
this chapter.
JSP.12.1.1 JspPage
Syntax
public interface JspPage extends javax.servlet.Servlet
2-17
2-18 CORE API
Description
The JspPage interface describes the generic interaction that a JSP Page Imple-
mentation class must satisfy; pages that use the HTTP protocol are described by
the HttpJspPage interface.
Two plus One Methods
The interface defines a protocol with 3 methods; only two of them: jspInit() and
jspDestroy() are part of this interface as the signature of the third method: _jsp-
Service() depends on the specific protocol used and cannot be expressed in a
generic way in Java.
A class implementing this interface is responsible for invoking the above methods
at the appropriate time based on the corresponding Servlet-based method invoca-
tions.
The jspInit() and jspDestroy() methods can be defined by a JSP author, but the
_jspService() method is defined automatically by the JSP processor based on the
contents of the JSP page.
_jspService()
The _jspService()method corresponds to the body of the JSP page. This method is
defined automatically by the JSP container and should never be defined by the
JSP page author.
If a superclass is specified using the extends attribute, that superclass may choose
to perform some actions in its service() method before or after calling the
_jspService() method. See using the extends attribute in the JSP_Engine chapter
of the JSP specification.
The specific signature depends on the protocol supported by the JSP page.
public void _jspService(ServletRequestSubtype request,
ServletResponseSubtype response)
throws ServletException, IOException;
JSP.12.1.1.1 Methods
public void jspDestroy()
The jspDestroy() method is invoked when the JSP page is about to be
destroyed. A JSP page can override this method by including a definition for
it in a declaration element. A JSP page should redefine the destroy() method
from Servlet.
JSP.12.1.2 HttpJspPage
Syntax
public interface HttpJspPage extends JspPage
Description
The HttpJspPage interface describes the interaction that a JSP Page Implementa-
tion Class must satisfy when using the HTTP protocol.
The behaviour is identical to that of the JspPage, except for the signature of the
_jspService method, which is now expressible in the Java type system and
included explicitly in the interface.
JSP.12.1.2.1 Methods
public void _jspService(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
The _jspService()method corresponds to the body of the JSP page. This
method is defined automatically by the JSP container and should never be
defined by the JSP page author.
If a superclass is specified using the extends attribute, that superclass may
choose to perform some actions in its service() method before or after calling
the _jspService() method. See using the extends attribute in the JSP_Engine
chapter of the JSP specification.
Parameters:
request - Provides client request information to the JSP.
response - Assists the JSP in sending a response to the client.
Throws:
ServletException - Thrown if an error occurred during the processing of the
JSP and that the container should take appropriate action to clean up the
request.
IOException - Thrown if an error occurred while writing the response for this
page.
JSP.12.1.3 JspFactory
Syntax
public abstract class JspFactory
Description
The JspFactory is an abstract class that defines a number of factory methods
available to a JSP page at runtime for the purposes of creating instances of vari-
ous interfaces and classes used to support the JSP implementation.
A conformant JSP Engine implementation will, during it’s initialization instanti-
ate an implementation dependent subclass of this class, and make it globally
available for use by JSP implementation classes by registering the instance cre-
ated with this class via the static setDefaultFactory() method.
The PageContext and the JspEngineInfo classes are the only implementation-
dependent classes that can be created from the factory.
JspFactory objects should not be used by JSP page authors.
JSP.12.1.3.1 Constructors
public JspFactory()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
JSP.12.1.3.2 Methods
public static synchronized JspFactory getDefaultFactory()
Returns the default factory for this implementation.
Returns: the default factory for this implementation
public abstract JspEngineInfo getEngineInfo()
called to get implementation-specific information on the current JSP engine.
Returns: a JspEngineInfo object describing the current JSP engine
JSP.12.1.4 JspEngineInfo
Syntax
public abstract class JspEngineInfo
Description
The JspEngineInfo is an abstract class that provides information on the current
JSP engine.
JSP.12.1.4.1 Constructors
public JspEngineInfo()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
JSP.12.1.4.2 Methods
public abstract java.lang.String getSpecificationVersion()
Return the version number of the JSP specification that is supported by this
JSP engine.
Specification version numbers that consists of positive decimal integers sepa-
rated by periods “.”, for example, “2.0” or “1.2.3.4.5.6.7”. This allows an
extensible number to be used to represent major, minor, micro, etc versions.
The version number must begin with a number.
Returns: the specification version, null is returned if it is not known
The PageContext object and the JspWriter are available by default as implicit
objects.
JSP.12.2.1 JspContext
Syntax
public abstract class JspContext
Description
JspContext serves as the base class for the PageContext class and abstracts all
information that is not specific to servlets. This allows for Simple Tag Extensions
to be used outside of the context of a request/response Servlet.
The JspContext provides a number of facilities to the page/component author and
page implementor, including:
•a single API to manage the various scoped namespaces
•a mechanism to obtain the JspWriter for output
•a mechanism to expose page directive attributes to the scripting environ-
ment
Methods Intended for Container Generated Code
Since: 2.0
JSP.12.2.1.1 Constructors
public JspContext()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
JSP.12.2.1.2 Methods
public abstract java.lang.Object findAttribute(java.lang.String name)
Searches for the named attribute in page, request, session (if valid), and appli-
cation scope(s) in order and returns the value associated or null.
Parameters:
The returned JspWriter must implement all methods and behave as though it
were unbuffered. More specifically:
•clear() must throw an IOException
•clearBuffer() does nothing
•getBufferSize() always returns 0
•getRemaining() always returns 0
Parameters:
writer - The Writer for the returned JspWriter to send output to.
Returns: a new JspWriter that writes to the given Writer.
Since: 2.0
public abstract void removeAttribute(java.lang.String name)
Remove the object reference associated with the given name from all scopes.
Does nothing if there is no such object.
Parameters:
name - The name of the object to remove.
Throws:
NullPointerException - if the name is null
public abstract void removeAttribute(java.lang.String name, int scope)
Remove the object reference associated with the specified name in the given
scope. Does nothing if there is no such object.
Parameters:
name - The name of the object to remove.
scope - The scope where to look.
Throws:
IllegalArgumentException - if the scope is invalid
IllegalStateException - if the scope is PageContext.SESSION_SCOPE but the
page that was requested does not participate in a session or the session has
been invalidated.
NullPointerException - if the name is null
public abstract void setAttribute(java.lang.String name, java.lang.Object value)
Register the name and value specified with page scope semantics. If the value
passed in is null, this has the same effect as calling removeAttribute( name,
PageContext.PAGE_SCOPE ).
Parameters:
name - the name of the attribute to set
value - the value to associate with the name, or null if the attribute is to be
removed from the page scope.
Throws:
NullPointerException - if the name is null
public abstract void setAttribute(java.lang.String name, java.lang.Object value,
int scope)
Register the name and value specified with appropriate scope semantics. If
the value passed in is null, this has the same effect as calling removeAttribute(
name, scope ).
Parameters:
name - the name of the attribute to set
value - the object to associate with the name, or null if the attribute is to be
removed from the specified scope.
scope - the scope with which to associate the name/object
Throws:
NullPointerException - if the name is null
IllegalArgumentException - if the scope is invalid
IllegalStateException - if the scope is PageContext.SESSION_SCOPE but the
page that was requested does not participate in a session or the session has
been invalidated.
JSP.12.2.2 PageContext
Syntax
public abstract class PageContext extends JspContext
Description
PageContext extends JspContext to provide useful context information for when
JSP technology is used in a Servlet environment.
A PageContext instance provides access to all the namespaces associated with a
JSP page, provides access to several page attributes, as well as a layer above the
implementation details. Implicit objects are added to the pageContext automati-
cally.
The PageContext class is an abstract class, designed to be extended to provide
implementation dependent implementations thereof, by conformant JSP engine
runtime environments. A PageContext instance is obtained by a JSP implementa-
Some methods are intended to be used by the code generated by the container, not
by code written by JSP page authors, or JSP tag library authors.
The methods supporting lifecycle are initialize() and release()
The following methods enable the management of nested JspWriter streams to
implement Tag Extensions: pushBody()
Methods Intended for JSP authors
The following methods provide convenient access to implicit objects: get-
Exception(), getPage() getRequest(), getResponse(), getSession(), getServlet-
Config() and getServletContext().
The following methods provide support for forwarding, inclusion and error
handling: forward(), include(), and handlePageException().
JSP.12.2.2.1 Fields
public static final java.lang.String APPLICATION
Name used to store ServletContext in PageContext name table.
public static final int APPLICATION_SCOPE
Application scope: named reference remains available in the ServletContext
until it is reclaimed.
public static final java.lang.String CONFIG
Name used to store ServletConfig in PageContext name table.
JSP.12.2.2.2 Constructors
public PageContext()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
JSP.12.2.2.3 Methods
public abstract void forward(java.lang.String relativeUrlPath)
This method is used to re-direct, or “forward” the current ServletRequest and
ServletResponse to another active component in the application.
If the relativeUrlPath begins with a “/” then the URL specified is calculated
relative to the DOCROOT of the ServletContext for this JSP. If the path does
not begin with a “/” then the URL specified is calculated relative to the URL
of the request that was mapped to the calling JSP.
It is only valid to call this method from a Thread executing within a _jsp-
Service(...) method of a JSP.
Once this method has been called successfully, it is illegal for the calling
Thread to attempt to modify the ServletResponse object. Any such attempt
to do so, shall result in undefined behavior. Typically, callers immediately
return from _jspService(...) after calling this method.
Parameters:
relativeUrlPath - specifies the relative URL path to the target resource as
described above
Throws:
IllegalStateException - if ServletResponse is not in a state where a forward
can be performed
ServletException - if the page that was forwarded to throws a
ServletException
IOException - if an I/O error occurred while forwarding
public ErrorData getErrorData()
Provides convenient access to error information.
Returns: an ErrorData instance containing information about the error, as
obtained from the request attributes, as per the Servlet specification. If this is
not an error page (that is, if the isErrorPage attribute of the page directive is
not set to “true”), the information is meaningless.
Since: 2.0
public abstract java.lang.Exception getException()
The current value of the exception object (an Exception).
Returns: any exception passed to this as an errorpage
public abstract java.lang.Object getPage()
The current value of the page object (In a Servlet environment, this is an
instance of javax.servlet.Servlet).
Returns: the Page implementation class instance associated with this
PageContext
public abstract javax.servlet.ServletRequest getRequest()
The current value of the request object (a ServletRequest).
It is only valid to call this method from a Thread executing within a _jsp-
Service(...) method of a JSP.
Parameters:
relativeUrlPath - specifies the relative URL path to the target resource to be
included
Throws:
ServletException - if the page that was forwarded to throws a
ServletException
IOException - if an I/O error occurred while forwarding
public abstract void include(java.lang.String relativeUrlPath, boolean flush)
Causes the resource specified to be processed as part of the current Servlet-
Request and ServletResponse being processed by the calling Thread. The
output of the target resources processing of the request is written directly to
the current JspWriter returned by a call to getOut().
If flush is true, The current JspWriter “out” for this JSP is flushed as a side-
effect of this call, prior to processing the include. Otherwise, the JspWriter
“out” is not flushed.
If the relativeUrlPath begins with a “/” then the URL specified is calculated
relative to the DOCROOT of the ServletContext for this JSP. If the path does
not begin with a “/” then the URL specified is calculated relative to the URL
of the request that was mapped to the calling JSP.
It is only valid to call this method from a Thread executing within a _jsp-
Service(...) method of a JSP.
Parameters:
relativeUrlPath - specifies the relative URL path to the target resource to be
included
flush - True if the JspWriter is to be flushed before the include, or false if not.
Throws:
ServletException - if the page that was forwarded to throws a
ServletException
IOException - if an I/O error occurred while forwarding
Since: 2.0
public abstract void initialize(javax.servlet.Servlet servlet,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response, java.lang.String errorPageURL,
boolean needsSession, int bufferSize, boolean autoFlush)
JSP.12.2.3 JspWriter
Syntax
public abstract class JspWriter extends java.io.Writer
Description
The actions and template data in a JSP page is written using the JspWriter object
that is referenced by the implicit variable out which is initialized automatically
using methods in the PageContext object.
This abstract class emulates some of the functionality found in the
java.io.BufferedWriter and java.io.PrintWriter classes, however it differs in that it
throws java.io.IOException from the print methods while PrintWriter does not.
Buffering
The initial JspWriter object is associated with the PrintWriter object of the
ServletResponse in a way that depends on whether the page is or is not buffered.
If the page is not buffered, output written to this JspWriter object will be written
through to the PrintWriter directly, which will be created if necessary by invoking
the getWriter() method on the response object. But if the page is buffered, the
PrintWriter object will not be created until the buffer is flushed and operations
like setContentType() are legal. Since this flexibility simplifies programming sub-
stantially, buffering is the default for JSP pages.
Buffering raises the issue of what to do when the buffer is exceeded. Two
approaches can be taken:
•Exceeding the buffer is not a fatal error; when the buffer is exceeded, just
flush the output.
•Exceeding the buffer is a fatal error; when the buffer is exceeded, raise an
exception.
Both approaches are valid, and thus both are supported in the JSP technology. The
behavior of a page is controlled by the autoFlush attribute, which defaults to true.
In general, JSP pages that need to be sure that correct and complete data has been
sent to their client may want to set autoFlush to false, with a typical case being
that where the client is an application itself. On the other hand, JSP pages that
send data that is meaningful even when partially constructed may want to set
autoFlush to true; such as when the data is sent for immediate display through a
browser. Each application will need to consider their specific needs.
An alternative considered was to make the buffer size unbounded; but, this had
the disadvantage that runaway computations would consume an unbounded
amount of resources.
The “out” implicit variable of a JSP implementation class is of this type. If the
page directive selects autoflush=“true” then all the I/O operations on this class
shall automatically flush the contents of the buffer if an overflow condition would
result if the current operation were performed without a flush. If autof-
lush=“false” then all the I/O operations on this class shall throw an IOException
if performing the current operation would result in a buffer overflow condition.
JSP.12.2.3.1 Fields
protected boolean autoFlush
Whether the JspWriter is autoflushing.
protected int bufferSize
The size of the buffer used by the JspWriter.
public static final int DEFAULT_BUFFER
Constant indicating that the Writer is buffered and is using the implementa-
tion default buffer size.
public static final int NO_BUFFER
Constant indicating that the Writer is not buffering output.
public static final int UNBOUNDED_BUFFER
Constant indicating that the Writer is buffered and is unbounded; this is used
in BodyContent.
JSP.12.2.3.2 Constructors
protected JspWriter(int bufferSize, boolean autoFlush)
Protected constructor.
Parameters:
bufferSize - the size of the buffer to be used by the JspWriter
autoFlush - whether the JspWriter should be autoflushing
JSP.12.2.3.3 Methods
public abstract void clear()
Clear the contents of the buffer. If the buffer has been already been flushed
then the clear operation shall throw an IOException to signal the fact that
some data has already been irrevocably written to the client response stream.
Throws:
IOException - If an I/O error occurs
public abstract void clearBuffer()
Clears the current contents of the buffer. Unlike clear(), this method will not
throw an IOException if the buffer has already been flushed. It merely clears
the current content of the buffer and returns.
Throws:
IOException - If an I/O error occurs
public abstract void close()
Close the stream, flushing it first.
This method needs not be invoked explicitly for the initial JspWriter as the
code generated by the JSP container will automatically include a call to
close().
Closing a previously-closed stream, unlike flush(), has no effect.
Overrides: java.io.Writer.close() in class java.io.Writer
Throws:
IOException - If an I/O error occurs
public abstract void flush()
Flush the stream. If the stream has saved any characters from the various
write() methods in a buffer, write them immediately to their intended destina-
tion. Then, if that destination is another character or byte stream, flush it.
Thus one flush() invocation will flush all the buffers in a chain of Writers and
OutputStreams.
The method may be invoked indirectly if the buffer size is exceeded.
Once a stream has been closed, further write() or flush() invocations will
cause an IOException to be thrown.
Overrides: java.io.Writer.flush() in class java.io.Writer
Throws:
IOException - If an I/O error occurs
public int getBufferSize()
This method returns the size of the buffer used by the JspWriter.
Returns: the size of the buffer in bytes, or 0 is unbuffered.
Print a long integer and then terminate the line. This method behaves as
though it invokes public abstract void print(long l) and then public abstract void
println() .
Parameters:
x - the long to write
Throws:
java.io.IOException - If an error occured while writing
public abstract void println(java.lang.Object x)
Print an Object and then terminate the line. This method behaves as though it
invokes public abstract void print(java.lang.Object obj) and then public abstract
void println() .
Parameters:
x - the Object to write
Throws:
java.io.IOException - If an error occured while writing
public abstract void println(java.lang.String x)
Print a String and then terminate the line. This method behaves as though it
invokes public abstract void print(java.lang.String s) and then public abstract
void println() .
Parameters:
x - the String to write
Throws:
java.io.IOException - If an error occured while writing
JSP.12.2.4 ErrorData
Syntax
public final class ErrorData
Description
Contains information about an error, for error pages. The information contained
in this instance is meaningless if not used in the context of an error page. To indi-
cate a JSP is an error page, the page author must set the isErrorPage attribute of
the page directive to “true”.
Since: 2.0
JSP.12.2.4.1 Constructors
public ErrorData(java.lang.Throwable throwable, int statusCode,
java.lang.String uri, java.lang.String servletName)
Creates a new ErrorData object.
Parameters:
throwable - The Throwable that is the cause of the error
statusCode - The status code of the error
uri - The request URI
servletName - The name of the servlet invoked
JSP.12.2.4.2 Methods
public java.lang.String getRequestURI()
Returns the request URI.
Returns: The request URI
public java.lang.String getServletName()
Returns the name of the servlet invoked.
Returns: The name of the servlet invoked
public int getStatusCode()
Returns the status code of the error.
Returns: The status code of the error
public java.lang.Throwable getThrowable()
Returns the Throwable that caused the error.
Returns: The Throwable that caused the error
JSP.12.4 Exceptions
The JspException class is the base class for all JSP exceptions. The JspTag-
Exception and SkipPageException exceptions are used by the tag extension mecha-
nism.
JSP.12.4.1 JspException
Syntax
public class JspException extends java.lang.Exception
Description
A generic exception known to the JSP engine; uncaught JspExceptions will result
in an invocation of the errorpage machinery.
JSP.12.4.1.1 Constructors
public JspException()
Construct a JspException.
public JspException(java.lang.String msg)
Constructs a new JSP exception with the specified message. The message can
be written to the server log and/or displayed for the user.
Parameters:
msg - a String specifying the text of the exception message
public JspException(java.lang.String message, java.lang.Throwable rootCause)
Constructs a new JSP exception when the JSP needs to throw an exception
and include a message about the “root cause” exception that interfered with
its normal operation, including a description message.
Parameters:
message - a String containing the text of the exception message
rootCause - the Throwable exception that interfered with the servlet’s normal
operation, making this servlet exception necessary
public JspException(java.lang.Throwable rootCause)
Constructs a new JSP exception when the JSP needs to throw an exception
and include a message about the “root cause” exception that interfered with
its normal operation. The exception’s message is based on the localized mes-
sage of the underlying exception.
This method calls the getLocalizedMessage method on the Throwable excep-
tion to get a localized exception message. When subclassing JspException,
this method can be overridden to create an exception message designed for a
specific locale.
Parameters:
rootCause - the Throwable exception that interfered with the JSP’s normal
operation, making the JSP exception necessary
JSP.12.4.1.2 Methods
public java.lang.Throwable getRootCause()
Returns the exception that caused this JSP exception.
JSP.12.4.2 JspTagException
Syntax
public class JspTagException extends JspException
Description
Exception to be used by a Tag Handler to indicate some unrecoverable error. This
error is to be caught by the top level of the JSP page and will result in an error
page.
JSP.12.4.2.1 Constructors
public JspTagException()
Constructs a new JspTagException with no message.
public JspTagException(java.lang.String msg)
Constructs a new JspTagException with the specified message. The message
can be written to the server log and/or displayed for the user.
Parameters:
msg - a String specifying the text of the exception message
public JspTagException(java.lang.String message,
java.lang.Throwable rootCause)
Constructs a new JspTagException when the JSP Tag needs to throw an
exception and include a message about the “root cause” exception that inter-
fered with its normal operation, including a description message.
Parameters:
message - a String containing the text of the exception message
rootCause - the Throwable exception that interfered with the JSP Tag’s
normal operation, making this JSP Tag exception necessary
Since: 2.0
public JspTagException(java.lang.Throwable rootCause)
Constructs a new JSP Tag exception when the JSP Tag needs to throw an
exception and include a message about the “root cause” exception that inter-
fered with its normal operation. The exception’s message is based on the
localized message of the underlying exception.
This method calls the getLocalizedMessage method on the Throwable excep-
tion to get a localized exception message. When subclassing JspTag-
Exception, this method can be overridden to create an exception message
designed for a specific locale.
Parameters:
rootCause - the Throwable exception that interfered with the JSP Tag’s
normal operation, making the JSP Tag exception necessary
Since: 2.0
JSP.12.4.3 SkipPageException
Syntax
public class SkipPageException extends JspException
Description
Exception to indicate the calling page must cease evaluation. Thrown by a simple
tag handler to indicate that the remainder of the page must not be evaluated. The
result is propagated back to the pagein the case where one tag invokes another (as
can be the case with tag files). The effect is similar to that of a Classic Tag Han-
dler returning Tag.SKIP_PAGE from doEndTag(). Jsp Fragments may also throw
this exception. This exception should not be thrown manually in a JSP page or tag
file - the behavior is undefined. The exception is intended to be thrown inside
SimpleTag handlers and in JSP fragments.
Since: 2.0
JSP.12.4.3.1 Constructors
public SkipPageException()
Creates a SkipPageException with no message.
public SkipPageException(java.lang.String message)
This chapter describes the details of tag handlers and other tag extension
classes as well as methods that are available to access the Tag Library Descriptor
files. This complements a previous chapter that described the Tag Library Descrip-
tor files formats and their use in taglib directives.
This chapter includes content that is generated automatically from javadoc
embedded into the actual Java classes and interfaces. This allows the creation of a
single, authoritative, specification document.
Custom actions can be used by JSP authors and authoring tools to simplify
writing JSP pages. A custom action can be either an empty or a non-empty action.
An empty tag has no body. There are two equivalent syntaxes, one with
separate start and an end tag, and one where the start and end tags are combined.
The two following examples are identical:
<x:foo att=“myObject” />
<x:foo att=“myObject” ></foo>
A non-empty tag has a start tag, a body, and an end tag. A prototypical example
is of the form:
<x:foo att=“myObject” >
BODY
</x:foo/>
The JavaServer Pages(tm) (JSP) 1.2 specification provides a portable mecha-
nism for the description of tag libraries containing:
•A Tag Library Descriptor (TLD)
•A number of Tag handler classes defining request-time behavior
•A number of classes defining translation-time behavior
•Additional resources used by the classes
This chapter is organized in three sections. The first section presents the basic
tag handler classes. The second section describes the more complex tag handlers
that need to access their body evaluation. The last section looks at translation-time
issues.
2-49
2-50 TAG EXTENSION API
This section introduces the notion of a tag handler and describes the classic
types of tag handler.
JSP 2.0 introduces a new type of Tag Handler called a Simple Tag Handler,
which is described in a later section in this chapter. The protocol for Simple Tag
handlers is much more straightforward.
Tag Handler
A tag handler is a run-time, container-managed, object that evaluates custom
actions during the execution of a JSP page. A tag handler supports a protocol that
allows the JSP container to provide good integration of the server-side actions
within a JSP page.
A tag handler is created initially using a zero argument constructor on its
corresponding class; the method java.beans.Beans.instantiate() is not used.
A tag handler has some properties that are exposed to the page as attributes on
an action; these properties are managed by the JSP container (via generated code).
The setter methods used to set the properties are discovered using the JavaBeans
introspector machinery.
The protocol supported by a tag handler provides for passing of parameters,
the evaluation and reevaluation of the body of the action, and for getting access to
objects and other tag handlers in the JSP page.
A tag handler instance is responsible for processing one request at a time. It is
the responsability of the JSP container to enforce this.
Additional translation time information associated with the action indicates
the name of any scripting variables it may introduce, their types and their scope.
At specific moments, the JSP container will automatically synchronize the Page-
Context information with variables in the scripting language so they can be made
available directly through the scripting elements.
Properties
A tag handler has some properties. All tag handlers have a pageContext prop-
erty for the JSP page where the tag is located, and a parent property for the tag han-
dler to the closest enclosing action. Specific tag handler classes may have additional
properties.
All attributes of a custom action must be JavaBeans component properties,
although some properties may not be exposed as attributes. The attributes that are
visible to the JSP translator are exactly those listed in the Tag Library Descriptor
(TLD).
hoist setting of properties to reduce cost when a tag handler is inside another
iterative tag.
Conversions
A tag handler implements an action; the JSP container must follow the type
conversions described in Section 2.13.2 when assigning values to the attributes of an
action.
JSP.13.1.1 JspTag
Syntax
public interface JspTag
Description
Serves as a base class for Tag and SimpleTag. This is mostly for organizational
and type-safety purposes.
Since: 2.0
JSP.13.1.2 Tag
Syntax
public interface Tag extends JspTag
Description
The interface of a classic tag handler that does not want to manipulate its body.
The Tag interface defines the basic protocol between a Tag handler and JSP page
implementation class. It defines the life cycle and the methods to be invoked at
start and end tag.
Properties
JavaServer Pages 2.0 Specification
2-54 TAG EXTENSION API
The Tag interface specifies the setter and getter methods for the core pageContext
and parent properties.
The JSP page implementation object invokes setPageContext and setParent, in
that order, before invoking doStartTag() or doEndTag().
Methods
There are two main actions: doStartTag and doEndTag. Once all appropriate
properties have been initialized, the doStartTag and doEndTag methods can be
invoked on the tag handler. Between these invocations, the tag handler is assumed
to hold a state that must be preserved. After the doEndTag invocation, the tag han-
dler is available for further invocations (and it is expected to have retained its
properties).
Lifecycle
Lifecycle details are described by the transition diagram below, with the follow-
ing comments:
•[1] This transition is intended to be for releasing long-term data. no guaran-
tees are assumed on whether any properties have been retained or not.
•[2] This transition happens if and only if the tag ends normally without rais-
ing an exception
•[3] Some setters may be called again before a tag handler is reused. For
instance, setParent() is called if it’s reused within the same page but at a dif-
ferent level, setPageContext() is called if it’s used in another page, and
attribute setters are called if the values differ or are expressed as request-time
attribute values.
•Check the TryCatchFinally interface for additional details related to excep-
tion handling and resource management.
Once all invocations on the tag handler are completed, the release method is
invoked on it. Once a release method is invoked all properties, including parent
and pageContext, are assumed to have been reset to an unspecified value. The
page compiler guarantees that release() will be invoked on the Tag handler before
the handler is released to the GC.
Empty and Non-Empty Action
If the TagLibraryDescriptor file indicates that the action must always have an
empty action, by an <body-content> entry of “empty”, then the doStartTag()
method must return SKIP_BODY.
Otherwise, the doStartTag() method may return SKIP_BODY or
EVAL_BODY_INCLUDE.
JSP.13.1.2.1 Fields
public static final int EVAL_BODY_INCLUDE
Evaluate body into existing out stream. Valid return value for doStartTag.
public static final int EVAL_PAGE
Continue evaluating the page. Valid return value for doEndTag().
public static final int SKIP_BODY
Skip body evaluation. Valid return value for doStartTag and doAfterBody.
public static final int SKIP_PAGE
Skip the rest of the page. Valid return value for doEndTag.
JSP.13.1.2.2 Methods
public int doEndTag()
Process the end tag for this instance. This method is invoked by the JSP page
implementation object on all Tag handlers.
This method will be called after returning from doStartTag. The body of the
action may or may not have been evaluated, depending on the return value of
doStartTag.
If this method returns EVAL_PAGE, the rest of the page continues to be eval-
uated. If this method returns SKIP_PAGE, the rest of the page is not evalu-
ated, the request is completed, and the doEndTag() methods of enclosing tags
are not invoked. If this request was forwarded or included from another page
(or Servlet), only the current page evaluation is stopped.
The JSP container will resynchronize the values of any AT_BEGIN and
AT_END variables (defined by the associated TagExtraInfo or TLD) after the
invocation of doEndTag().
Returns: indication of whether to continue evaluating the JSP page.
Throws:
JspException - if an error occurred while processing this tag
public int doStartTag()
Process the start tag for this instance. This method is invoked by the JSP page
implementation object.
The doStartTag method assumes that the properties pageContext and parent
have been set. It also assumes that any properties exposed as attributes have
been set too. When this method is invoked, the body has not yet been evalu-
ated.
This method returns Tag.EVAL_BODY_INCLUDE or Body-
Tag.EVAL_BODY_BUFFERED to indicate that the body of the action
should be evaluated or SKIP_BODY to indicate otherwise.
When a Tag returns EVAL_BODY_INCLUDE the result of evaluating the
body (if any) is included into the current “out” JspWriter as it happens and
then doEndTag() is invoked.
BodyTag.EVAL_BODY_BUFFERED is only valid if the tag handler imple-
ments BodyTag.
The JSP container will resynchronize the values of any AT_BEGIN and
NESTED variables (defined by the associated TagExtraInfo or TLD) after the
invocation of doStartTag(), except for a tag handler implementing BodyTag
whose doStartTag() method returns BodyTag.EVAL_BODY_BUFFERED.
Returns: EVAL_BODY_INCLUDE if the tag wants to process body,
SKIP_BODY if it does not want to process it.
Throws:
JspException - if an error occurred while processing this tag
See Also: BodyTag
public Tag getParent()
Get the parent (closest enclosing tag handler) for this tag handler.
The getParent() method can be used to navigate the nested tag handler struc-
ture at runtime for cooperation among custom actions; for example, the find-
AncestorWithClass() method in TagSupport provides a convenient way of
doing this.
The current version of the specification only provides one formal way of indi-
cating the observable type of a tag handler: its tag handler implementation
class, described in the tag-class subelement of the tag element. This is
extended in an informal manner by allowing the tag library author to indicate
in the description subelement an observable type. The type should be a sub-
type of the tag handler implementation class or void. This addititional con-
straint can be exploited by a specialized container that knows about that
specific tag library, as in the case of the JSP standard tag library.
Returns: the current parent, or null if none.
See Also: public static final Tag findAncestorWithClass(Tag from,
java.lang.Class klass)
JavaServer Pages 2.0 Specification
2-58 TAG EXTENSION API
JSP.13.1.3 IterationTag
Syntax
public interface IterationTag extends Tag
Description
The IterationTag interface extends Tag by defining one additional method that
controls the reevaluation of its body.
A tag handler that implements IterationTag is treated as one that implements Tag
regarding the doStartTag() and doEndTag() methods. IterationTag provides a new
method: doAfterBody().
The doAfterBody() method is invoked after every body evaluation to control
whether the body will be reevaluated or not. If doAfterBody() returns Iteration-
Tag.EVAL_BODY_AGAIN, then the body will be reevaluated. If doAfterBody()
returns Tag.SKIP_BODY, then the body will be skipped and doEndTag() will be
evaluated instead.
Properties There are no new properties in addition to those in Tag.
Methods There is one new methods: doAfterBody().
Lifecycle
Lifecycle details are described by the transition diagram below. Exceptions that
are thrown during the computation of doStartTag(), BODY and doAfterBody()
interrupt the execution sequence and are propagated up the stack, unless the tag
handler implements the TryCatchFinally interface; see that interface for details.
JSP.13.1.3.1 Fields
public static final int EVAL_BODY_AGAIN
Request the reevaluation of some body. Returned from doAfterBody. For
compatibility with JSP 1.1, the value is carefully selected to be the same as
the, now deprecated, BodyTag.EVAL_BODY_TAG,
JSP.13.1.3.2 Methods
public int doAfterBody()
Process body (re)evaluation. This method is invoked by the JSP Page imple-
mentation object after every evaluation of the body into the BodyEvaluation
object. The method is not invoked if there is no body evaluation.
If doAfterBody returns EVAL_BODY_AGAIN, a new evaluation of the body
will happen (followed by another invocation of doAfterBody). If doAfter-
Body returns SKIP_BODY, no more body evaluations will occur, and the
doEndTag method will be invoked.
If this tag handler implements BodyTag and doAfterBody returns
SKIP_BODY, the value of out will be restored using the popBody method in
pageContext prior to invoking doEndTag.
The method re-invocations may be lead to different actions because there
might have been some changes to shared state, or because of external compu-
tation.
The JSP container will resynchronize the values of any AT_BEGIN and
NESTED variables (defined by the associated TagExtraInfo or TLD) after the
invocation of doAfterBody().
Returns: whether additional evaluations of the body are desired
Throws:
JspException - if an error occurred while processing this tag
JSP.13.1.4 TryCatchFinally
Syntax
public interface TryCatchFinally
Description
The auxiliary interface of a Tag, IterationTag or BodyTag tag handler that wants
additional hooks for managing resources.
This interface provides two new methods: doCatch(Throwable) and doFinally().
The prototypical invocation is as follows:
h = get a Tag(); // get a tag handler, perhaps from pool
h.setPageContext(pc); // initialize as desired
h.setParent(null);
h.setFoo(“foo”);
JSP.13.1.4.1 Methods
public void doCatch(java.lang.Throwable t)
JSP.13.1.5 TagSupport
Syntax
public class TagSupport implements IterationTag, java.io.Serializable
Description
A base class for defining new tag handlers implementing Tag.
JavaServer Pages 2.0 Specification
Classic Tag Handlers 2-63
The TagSupport class is a utility class intended to be used as the base class for
new tag handlers. The TagSupport class implements the Tag and IterationTag
interfaces and adds additional convenience methods including getter methods for
the properties in Tag. TagSupport has one static method that is included to facili-
tate coordination among cooperating tags.
Many tag handlers will extend TagSupport and only redefine a few methods.
JSP.13.1.5.1 Fields
protected java.lang.String id
The value of the id attribute of this tag; or null.
protected PageContext pageContext
The PageContext.
JSP.13.1.5.2 Constructors
public TagSupport()
Default constructor, all subclasses are required to define only a public con-
structor with the same signature, and to call the superclass constructor. This
constructor is called by the code generated by the JSP translator.
JSP.13.1.5.3 Methods
public int doAfterBody()
Default processing for a body.
Returns: SKIP_BODY
Throws:
JspException - if an error occurs while processing this tag
See Also: public int doAfterBody()
public int doEndTag()
Default processing of the end tag returning EVAL_PAGE.
Returns: EVAL_PAGE
Throws:
JspException - if an error occurs while processing this tag
See Also: public int doEndTag()
public int doStartTag()
Default processing of the start tag, returning SKIP_BODY.
Returns: SKIP_BODY
Throws:
JspException - if an error occurs while processing this tag
See Also: public int doStartTag()
public static final Tag findAncestorWithClass(Tag from, java.lang.Class klass)
Find the instance of a given class type that is closest to a given instance. This
method uses the getParent method from the Tag interface. This method is
used for coordination among cooperating tags.
The current version of the specification only provides one formal way of indi-
cating the observable type of a tag handler: its tag handler implementation
class, described in the tag-class subelement of the tag element. This is
extended in an informal manner by allowing the tag library author to indicate
in the description subelement an observable type. The type should be a sub-
type of the tag handler implementation class or void. This addititional con-
straint can be exploited by a specialized container that knows about that
specific tag library, as in the case of the JSP standard tag library.
When a tag library author provides information on the observable type of a
tag handler, client programmatic code should adhere to that constraint. Spe-
cifically, the Class passed to findAncestorWithClass should be a subtype of
the observable type.
Parameters:
from - The instance from where to start looking.
klass - The subclass of Tag or interface to be matched
Returns: the nearest ancestor that implements the interface or is an instance
of the class specified
public java.lang.String getId()
The value of the id attribute of this tag; or null.
Returns: the value of the id attribute, or null
public Tag getParent()
The Tag instance most closely enclosing this tag instance.
Returns: the parent tag instance or null
See Also: public Tag getParent()
public java.lang.Object getValue(java.lang.String k)
Get a the value associated with a key.
Parameters:
JSP.13.2.1 BodyContent
Syntax
public abstract class BodyContent extends JspWriter
Description
An encapsulation of the evaluation of the body of an action so it is available to a
tag handler. BodyContent is a subclass of JspWriter.
Note that the content of BodyContent is the result of evaluation, so it will not con-
tain actions and the like, but the result of their invocation.
BodyContent has methods to convert its contents into a String, to read its con-
tents, and to clear the contents.
The buffer size of a BodyContent object is unbounded. A BodyContent object
cannot be in autoFlush mode. It is not possible to invoke flush on a BodyContent
object, as there is no backing stream.
Instances of BodyContent are created by invoking the pushBody and popBody
methods of the PageContext class. A BodyContent is enclosed within another
JspWriter (maybe another BodyContent object) following the structure of their
associated actions.
A BodyContent is made available to a BodyTag through a setBodyContent() call.
The tag handler can use the object until after the call to doEndTag().
JSP.13.2.1.1 Constructors
protected BodyContent(JspWriter e)
Protected constructor. Unbounded buffer, no autoflushing.
Parameters:
e - the enclosing JspWriter
JSP.13.2.1.2 Methods
public void clearBody()
Clear the body without throwing any exceptions.
public void flush()
Redefined flush() so it is not legal.
It is not valid to flush a BodyContent because there is no backing stream
behind it.
Overrides: public abstract void flush() in class JspWriter
Throws:
IOException - always thrown
public JspWriter getEnclosingWriter()
Get the enclosing JspWriter.
Returns: the enclosing JspWriter passed at construction time
public abstract java.io.Reader getReader()
Return the value of this BodyContent as a Reader.
JavaServer Pages 2.0 Specification
2-68 TAG EXTENSION API
JSP.13.2.2 BodyTag
Syntax
public interface BodyTag extends IterationTag
Description
The BodyTag interface extends IterationTag by defining additional methods that
let a tag handler manipulate the content of evaluating its body.
It is the responsibility of the tag handler to manipulate the body content. For
example the tag handler may take the body content, convert it into a String using
the bodyContent.getString method and then use it. Or the tag handler may take
the body content and write it out into its enclosing JspWriter using the body-
Content.writeOut method.
A tag handler that implements BodyTag is treated as one that implements
IterationTag, except that the doStartTag method can return SKIP_BODY,
EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED.
If EVAL_BODY_INCLUDE is returned, then evaluation happens as in Iteration-
Tag.
evaluated and “passed through” to the current out, doAfterBody() is invoked and
then, after zero or more iterations, doEndTag() is invoked. If the custom action
element is empty, only doStart() and doEndTag() are invoked.
If EVAL_BODY_BUFFERED is returned, and the custom action element is not
empty, setBodyContent() is invoked, doInitBody() is invoked, the body is evalu-
ated, doAfterBody() is invoked, and then, after zero or more iterations, doEnd-
Tag() is invoked. If the custom action element is empty, only doStart() and
doEndTag() are invoked.
JSP.13.2.2.1 Fields
public static final int EVAL_BODY_BUFFERED
Request the creation of new buffer, a BodyContent on which to evaluate the
body of this tag. Returned from doStartTag when it implements BodyTag.
This is an illegal return value for doStartTag when the class does not imple-
ment BodyTag.
public static final int EVAL_BODY_TAG
Deprecated. As of Java JSP API 1.2, use
BodyTag.EVAL_BODY_BUFFERED or
IterationTag.EVAL_BODY_AGAIN.
Deprecated constant that has the same value as EVAL_BODY_BUFFERED
and EVAL_BODY_AGAIN. This name has been marked as deprecated to
encourage the use of the two different terms, which are much more descrip-
tive.
JSP.13.2.2.2 Methods
public void doInitBody()
Prepare for evaluation of the body. This method is invoked by the JSP page
implementation object after setBodyContent and before the first time the
body is to be evaluated. This method will not be invoked for empty tags or for
non-empty tags whose doStartTag() method returns SKIP_BODY or
EVAL_BODY_INCLUDE.
The JSP container will resynchronize the values of any AT_BEGIN and
NESTED variables (defined by the associated TagExtraInfo or TLD) after the
invocation of doInitBody().
Throws:
JspException - if an error occurred while processing this tag
See Also: public int doAfterBody()
public void setBodyContent(BodyContent b)
Set the bodyContent property. This method is invoked by the JSP page imple-
mentation object at most once per action invocation. This method will be
invoked before doInitBody. This method will not be invoked for empty tags
or for non-empty tags whose doStartTag() method returns SKIP_BODY or
EVAL_BODY_INCLUDE.
When setBodyContent is invoked, the value of the implicit object out has
already been changed in the pageContext object. The BodyContent object
passed will have not data on it but may have been reused (and cleared) from
some previous invocation.
The BodyContent object is available and with the appropriate content until
after the invocation of the doEndTag method, at which case it may be reused.
Parameters:
b - the BodyContent
See Also: public void doInitBody(), public int doAfterBody()
JSP.13.2.3 BodyTagSupport
Syntax
public class BodyTagSupport extends TagSupport implements BodyTag
Description
A base class for defining tag handlers implementing BodyTag.
The BodyTagSupport class implements the BodyTag interface and adds addi-
tional convenience methods including getter methods for the bodyContent prop-
erty and methods to get at the previous out JspWriter.
Many tag handlers will extend BodyTagSupport and only redefine a few methods.
JSP.13.2.3.1 Fields
protected BodyContent bodyContent
The current BodyContent for this BodyTag.
JSP.13.2.3.2 Constructors
public BodyTagSupport()
Default constructor, all subclasses are required to only define a public con-
structor with the same signature, and to call the superclass constructor. This
constructor is called by the code generated by the JSP translator.
JSP.13.2.3.3 Methods
public int doAfterBody()
After the body evaluation: do not reevaluate and continue with the page. By
default nothing is done with the bodyContent data (if any).
Overrides: public int doAfterBody() in class TagSupport
Returns: SKIP_BODY
Throws:
JspException - if an error occurred while processing this tag
See Also: public void doInitBody(), public int doAfterBody()
public int doEndTag()
Default processing of the end tag returning EVAL_PAGE.
Overrides: public int doEndTag() in class TagSupport
Returns: EVAL_PAGE
Throws:
JspException - if an error occurred while processing this tag
See Also: public int doEndTag()
public void doInitBody()
Prepare for evaluation of the body just before the first body evaluation: no
action.
Throws:
JspException - if an error occurred while processing this tag
See Also: public void setBodyContent(BodyContent b), public int
doAfterBody(), public void doInitBody()
public int doStartTag()
Default processing of the start tag returning EVAL_BODY_BUFFERED.
Overrides: public int doStartTag() in class TagSupport
Returns: EVAL_BODY_BUFFERED
Throws:
JspException - if an error occurred while processing this tag
See Also: public int doStartTag()
Any tag handler can optionally extend the DynamicAttributes interface to indi-
cate that it supports dynamic attributes. In addition to implementing the Dynamic-
Attributes interface, tag handlers that support dynamic attributes must declare that
they do so in the Tag Library Descriptor.
The TLD is what ultimately determines whether a tag handler accepts
dynamic attributes or not. If a tag handler declares that it supports dynamic
attributes in the TLD but it does not implement the DynamicAttributes interface, the
tag handler must be considered invalid by the container.
If the dynamic-attributes element for a tag being invoked contains the value
“true”, the following requirements apply:
•For each attribute specified in the tag invocation that does not have a corre-
sponding attribute element in the TLD for this tag, a call must be made to set-
DynamicAttribute(), passing in the namespace of the attribute (or null if the
attribute does not have a namespace or prefix), the name of the attribute with-
out the namespace prefix, and the final value of the attribute.
•Dynamic attributes must be considered to accept request-time expression
values.
JSP.13.3.1 DynamicAttributes
Syntax
public interface DynamicAttributes
Description
For a tag to declare that it accepts dynamic attributes, it must implement this
interface. The entry for the tag in the Tag Library Descriptor must also be config-
ured to indicate dynamic attributes are accepted.
For any attribute that is not declared in the Tag Library Descriptor for this tag,
instead of getting an error at translation time, the setDynamicAttribute() method is
called, with the name and value of the attribute. It is the responsibility of the tag
to remember the names and values of the dynamic attributes.
Since: 2.0
JSP.13.3.1.1 Methods
public void setDynamicAttribute(java.lang.String uri, java.lang.String localName,
java.lang.Object value)
Called when a tag declared to accept dynamic attributes is passed an attribute
that is not declared in the Tag Library Descriptor.
Parameters:
uri - the namespace of the attribute, or null if in the default namespace.
localName - the name of the attribute being set.
value - the value of the attribute
Throws:
JspException - if the tag handler wishes to signal that it does not accept the
given attribute. The container must not call doStartTag() or doTag() for this
tag.
Below is a somewhat complete example of the way one JSP container could
choose to do some tag handler management. There are many other strategies that
could be followed, with different pay offs.
The example is as below. In this example, we are assuming that x:iterate is an
iterative tag, while x:doit and x:foobar are simple tag. We will also assume that
x:iterate and x:foobar implement the TryCatchFinally interface, while x:doit does
not.
<x:iterate src=“foo”>
<x:doit att1=“one” att2=“<%= 1 + 1 %>” />
<x:foobar />
<x:doit att1=“one” att2=“<%= 2 + 2 %>” />
</x:iterate>
<x:doit att1=“one” att2=“<%= 3 + 3 %>” />
The particular code shown below assumes there is some pool of tag handlers
that are managed (details not described, although pool managing is simpler when
there are no optional attributes), and attemps to reuse tag handlers if possible. The
code also “hoists” setting of properties to reduce the cost when appropriate, e.g.
inside an iteration.
// third invocation
// this tag handler could be reused from the previous ones.
d = get tag from pool or new();
d.setPageContext(pc);
d.setParent(null);
d.setAtt1(“one”);
d.setAtt2(3+3);
if ((b1 = d.doStartTag()) == EVAL_BODY_INCLUDE) {
// nothing
} else if (b1 != SKIP_BODY) {
// Q? protocol error
}
if ((b1 = d.doEndTag()) == SKIP_PAGE) {
break page; // be done with it.
} else if (b1 != EVAL_PAGE) {
// Q? protocol error
}
} catch (Throwable t) {
Actions can cooperate with other actions and with scripting code in a number of
ways.
PageContext
Often two actions in a JSP page will want to cooperate, perhaps by one action
creating some server-side object that needs to be access by another. One mechanism
for doing this is by giving the object a name within the JSP page; the first action will
create the object and associate the name to it while the second action will use the
name to retrieve the object.
For example, in the following JSP segment the foo action might create a
server-side object and give it the name “myObject”. Then the bar action might
access that server-side object and take some action.
<x:foo id=“myObject” />
<x:bar ref=“myObjet” />
In a JSP implementation, the mapping “name”->value is kept by the implicit
object pageContext. This object is passed around through the Tag handler instances
so it can be used to communicate information: all it is needed is to know the name
under which the information is stored into the pageContext.
This section presents the API to implement Simple Tag Handlers and JSP Frag-
ments. Simple Tag Handlers present a much simpler invocation protocol than do
Classic Tag Handlers.
The Tag Library Descriptor maps tag library declarations to their physical
underlying implementations. A Simple Tag Handler is represented in Java by a
class which implements the SimpleTag interface.
Unlike classic tag handlers, the SimpleTag interface does not extend Tag.
Instead of supporting doStartTag() and doEndTag(), the SimpleTag interface
provides a simple doTag() method, which is called once and only once for any
given tag invocation. All tag logic, iteration, body evaluations, etc. are to be
performed in this single method. Thus, simple tag handlers have the equivalent
power of BodyTag, but with a much simpler lifecycle and interface.
To support body content, the setJspBody() method is provided. The container
invokes the setJspBody() method with a JspFragment object encapsulating the
body of the tag. The tag handler implementation can call invoke() on that fragment
to evaluate the body. The SimpleTagSupport convenience class provides getJsp-
Body() and other useful methods to make this even easier.
•If the attribute is a scripting expression (e.g. “<%= 1+1 %>” in JSP syntax,
or “%= 1+1 %” in XML syntax), the expression is evaluated, and the result is
converted as per the rules in “Type Conversions”, and passed to the setter.
•Otherwise, if the attribute contains any Expression Language expressions
(e.g. “Hello ${name}”), the expression is evaluated, and the result is con-
verted and passed to the setter.
•Otherwise, the attribute value is taken verbatim, converted, and passed to the
setter.
4. The value for each <jsp:attribute> element is evaluated, and the corresponding
bean property setter methods are invoked for each, in the order in which they
appear in the body of the tag. If no setter is defined for the specified attribute but
the tag accepts dynamic attributes, the setDynamicAttribute() method is invoked as
the setter.
•Otherwise, if the attribute is not of type JspFragment, the container evaluates
the body of the <jsp:attribute> element. This evaluation can be done in a con-
tainer-specific manner. Container implementors should note that in the pro-
cess of evaluating this body, other custom actions may be invoked.
•Otherwise, if the attribute is of type JspFragment, an instance of a Jsp-
Fragment object is created and passed in.
5. The value for the body of the tag is determined, and if a body exists the setJsp-
Body() method is called on the tag handler.
•If the tag is declared to have a body-content of “empty” or no body or an
empty body is passed for this invocation, then setJspBody() is not called.
•Otherwise, the body of the tag is either the body of the <jsp:body> element,
or the body of the custom action invocation if no <jsp:body> or
<jsp:attribute> elements are present. In this case, an instance of a Jsp-
Fragment object is created as per the lifecycle described in the JSP Fragments
section and it is passed to the setter. If the tag is declared to have a body-con-
tent of “tagdependent” the JspFragment must echo the body’s contents verba-
tim. Otherwise, if the tag is declared to have a body-content of type
“scriptless”, the JspFragment must evaluate the body’s contents as a JSP
scriptless body.
6. The doTag() method is invoked.
7. The implementation of doTag() performs its function, potentially calling other tag
handlers (if the tag handler is implemented as a tag file) and invoking fragments.
8. The doTag() method returns, and the tag handler instance is discarded. If Skip-
PageException is thrown, the rest of the page is not evaluated and the request is
completed. If this request was forwarded or included from another page (or Serv-
let), only the current page evaluation stops.
9. For each tag scripting variable declared with scopes AT_BEGIN or AT_END, the
appropriate scripting variables and scoped attributes are declared, as with classic
JavaServer Pages 2.0 Specification
2-82 TAG EXTENSION API
tag handlers.
JSP.13.6.1 SimpleTag
Syntax
public interface SimpleTag extends JspTag
Description
Interface for defining Simple Tag Handlers.
Simple Tag Handlers differ from Classic Tag Handlers in that instead of support-
ing doStartTag() and doEndTag(), the SimpleTag interface provides a simple
doTag() method, which is called once and only once for any given tag invocation.
All tag logic, iteration, body evaluations, etc. are to be performed in this single
method. Thus, simple tag handlers have the equivalent power of BodyTag, but
with a much simpler lifecycle and interface.
To support body content, the setJspBody() method is provided. The container
invokes the setJspBody() method with a JspFragment object encapsulating the
body of the tag. The tag handler implementation can call invoke() on that fragment
to evaluate the body as many times as it needs.
A SimpleTag handler must have a public no-args constructor. Most SimpleTag
handlers should extend SimpleTagSupport.
Lifecycle
The following is a non-normative, brief overview of the SimpleTag lifecycle.
Refer to the JSP Specification for details.
1. A new tag handler instance is created each time by the container by calling the
provided zero-args constructor. Unlike classic tag handlers, simple tag handlers
are never cached and reused by the JSP container.
2. The setJspContext() and setParent() methods are called by the container. The set-
Parent() method is only called if the element is nested within another tag invoca-
tion.
3. The setters for each attribute defined for this tag are called by the container.
4. If a body exists, the setJspBody() method is called by the container to set the body
of this tag, as a JspFragment. If the action element is empty in the page, this
Since: 2.0
JSP.13.6.1.1 Methods
public void doTag()
Called by the container to invoke this tag. The implementation of this method
is provided by the tag library developer, and handles all tag processing, body
iteration, etc.
The JSP container will resynchronize any AT_BEGIN and AT_END vari-
ables (defined by the associated tag file, TagExtraInfo, or TLD) after the
invocation of doTag().
Throws:
JspException - If an error occurred while processing this tag.
SkipPageException - If the page that (either directly or indirectly) invoked
this tag is to cease evaluation. A Simple Tag Handler generated from a tag file
must throw this exception if an invoked Classic Tag Handler returned
SKIP_PAGE or if an invoked Simple Tag Handler threw SkipPageException
or if an invoked Jsp Fragment threw a SkipPageException.
java.io.IOException - If there was an error writing to the output stream.
public JspTag getParent()
Returns the parent of this tag, for collaboration purposes.
Returns: the parent of this tag
public void setJspBody(JspFragment jspBody)
Provides the body of this tag as a JspFragment object, able to be invoked zero
or more times by the tag handler.
This method is invoked by the JSP page implementation object prior to
doTag(). If the action element is empty in the page, this method is not called
at all.
Parameters:
jspBody - The fragment encapsulating the body of this tag.
JSP.13.6.2 SimpleTagSupport
Syntax
public class SimpleTagSupport implements SimpleTag
Description
A base class for defining tag handlers implementing SimpleTag.
The SimpleTagSupport class is a utility class intended to be used as the base class
for new simple tag handlers. The SimpleTagSupport class implements the
SimpleTag interface and adds additional convenience methods including getter
methods for the properties in SimpleTag.
Since: 2.0
JSP.13.6.2.1 Constructors
public SimpleTagSupport()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
JSP.13.6.2.2 Methods
public void doTag()
JSP.13.6.3 TagAdapter
Syntax
public class TagAdapter implements Tag
Description
Wraps any SimpleTag and exposes it using a Tag interface. This is used to allow
collaboration between classic Tag handlers and SimpleTag handlers.
Because SimpleTag does not extend Tag, and because Tag.setParent() only
accepts a Tag instance, a classic tag handler (one that implements Tag) cannot
have a SimpleTag as its parent. To remedy this, a TagAdapter is created to wrap
the SimpleTag parent, and the adapter is passed to setParent() instead. A classic
Tag Handler can call getAdaptee() to retrieve the encapsulated SimpleTag
instance.
Since: 2.0
JSP.13.6.3.1 Constructors
public TagAdapter(SimpleTag adaptee)
Creates a new TagAdapter that wraps the given SimpleTag and returns the
parent tag when getParent() is called.
Parameters:
adaptee - The SimpleTag being adapted as a Tag.
JSP.13.6.3.2 Methods
public int doEndTag()
Must not be called.
Returns: always throws UnsupportedOperationException
Throws:
UnsupportedOperationException - Must not be called
JspException - never thrown
public int doStartTag()
Must not be called.
Returns: always throws UnsupportedOperationException
Throws:
UnsupportedOperationException - Must not be called
JspException - never thrown
public JspTag getAdaptee()
Gets the tag that is being adapted to the Tag interface. This should be an
instance of SimpleTag in JSP 2.0, but room is left for other kinds of tags in
future spec versions.
Returns: the tag that is being adapted
public Tag getParent()
Returns the parent of this tag, which is always getAdaptee().getParent(). This
will either be the enclosing Tag (if getAdaptee().getParent() implements
Tag), or an adapter to the enclosing Tag (if getAdaptee().getParent() does not
implement Tag).
Returns: The parent of the tag being adapted.
public void release()
Must not be called.
Throws:
UnsupportedOperationException - Must not be called
public void setPageContext(PageContext pc)
Must not be called.
Parameters:
pc - ignored.
Throws:
UnsupportedOperationException - Must not be called
public void setParent(Tag parentTag)
Must not be called. The parent of this tag is always getAdaptee().getParent().
Parameters:
parentTag - ignored.
Throws:
UnsupportedOperationException - Must not be called.
JSP.13.7.1 JspFragment
Syntax
public abstract class JspFragment
Description
Encapsulates a portion of JSP code in an object that can be invoked as many times
as needed. JSP Fragments are defined using JSP syntax as the body of a tag for an
invocation to a SimpleTag handler, or as the body of a <jsp:attribute> standard
action specifying the value of an attribute that is declared as a fragment, or to be
of type JspFragment in the TLD.
The definition of the JSP fragment must only contain template text and JSP action
elements. In other words, it must not contain scriptlets or scriptlet expressions.
At translation time, the container generates an implementation of the Jsp-
Fragment abstract class capable of executing the defined fragment.
A tag handler can invoke the fragment zero or more times, or pass it along to
other tags, before returning. To communicate values to/from a JSP fragment, tag
handlers store/retrieve values in the JspContext associated with the fragment.
Note that tag library developers and page authors should not generate Jsp-
Fragment implementations manually.
Implementation Note: It is not necessary to generate a separate class for each
fragment. One possible implementation is to generate a single helper class for
each page that implements JspFragment. Upon construction, a discriminator can
be passed to select which fragment that instance will execute.
Since: 2.0
JSP.13.7.1.1 Constructors
public JspFragment()
JSP.13.7.1.2 Methods
public abstract JspContext getJspContext()
Returns the JspContext that is bound to this JspFragment.
Returns: The JspContext used by this fragment at invocation time.
public abstract void invoke(java.io.Writer out)
Executes the fragment and directs all output to the given Writer, or the Jsp-
Writer returned by the getOut() method of the JspContext associated with the
fragment if out is null.
Parameters:
out - The Writer to output the fragment to, or null if output should be sent to
JspContext.getOut().
Throws:
JspException - Thrown if an error occured while invoking this fragment.
SkipPageException - Thrown if the page that (either directly or indirectly)
invoked the tag handler that invoked this fragment is to cease evaluation. The
container must throw this exception if a Classic Tag Handler returned
Tag.SKIP_PAGE or if a Simple Tag Handler threw SkipPageException.
java.io.IOException - If there was an error writing to the stream.
out = this.jspContext.getOut();
}
else {
out = this.jspContext.pushBody( writer );
}
// Step F.5 - Evaluate body of fragment:
try {
out.write( “Fragment Template Text ” );
out.write( jspContext.getExpressionEvaluator().evaluate(
“${var1}”,
java.lang.String.class,
vResolver, fMapper, “my” ) );
}
finally {
// Step F.6 - Restore value of JspContext.getOut()
if( writer != null ) {
this.jspContext.popBody();
}
}
// Step F.7-F.9 done in tag file (see following example)
}
} );
// Step T.5 - Determine and set body of the tag
// - body of tag
_jsp_mySimpleTag.setJspBody(
// Step C.1 - New instance of fragment created
// Step C.2 - Store jspContext
// Step C.3 - Association with nearest enclosing Tag instance
new JspFragmentBase( jspContext, _jsp_mySimpleTag ) {
public void invoke( java.io.Writer writer ) {
javax.servlet.jsp.JspWriter out;
// Step F.1-F.3 done in tag file (see following example)
// Step F.4 - If writer provided, push body:
if( writer == null ) {
out = this.jspContext.getOut();
}
else {
out = this.jspContext.pushBody( writer );
}
// Step F.5 - Evaluate body of fragment:
try {
out.write(
“Body of tag that defines an AT_BEGIN\n” +
“ scripting variable ” );
out.write( jspContext.getExpressionEvaluator().evaluate(
“${var1}”,
java.lang.String.class,
vResolver, fMapper, “my” ) );
out.write( “.\n” );
}
finally {
// Step F.6 - Restore value of JspContext.getOut()
if( writer != null ) {
this.jspContext.popBody();
}
}
// Step F.7-F.9 done in tag file (see following example)
}
} );
// Step T.6 - Inovke doTag
// Step T.7 occurs in the tag file (see following example)
// Step T.8 - doTag returns - page will catch SkipPageException.
_jsp_mySimpleTag.doTag();
// Step T.9 - Declare AT_BEGIN and AT_END scripting variables
String var1 = (String)jspContext.findAttribute( “var1” );
with tag names. This information is used to associate a Tag class, a prefix, and a
name with each custom action element appearing in a JSP page.
At execution time the implementation of a JSP page will use an available Tag
instance with the appropriate property settings and then follow the protocol
described by the interfaces Tag, IterationTag, BodyTag, SimpleTag, and Try-
CatchFinally. The implementation guarantees that all tag handler instances are
initialized and all are released, but the implementation can assume that previous
settings are preserved by a tag handler, to reduce run-time costs.
Scripting Variables
JSP supports scripting variables that can be declared within a scriptlet and can
be used in another. JSP actions also can be used to define scripting variables so they
can used in scripting elements, or in other actions. This is very useful in some cases;
for example, the jsp:useBean standard action may define an object which can later
be used through a scripting variable.
In some cases the information on scripting variables can be described directly
into the TLD using elements. A special case is typical interpretation of the “id”
attribute. In other cases the logic that decides whether an action instance will
define a scripting variable may be quite complex and the name of a TagExtraInfo
class is instead given in the TLD. The getVariableInfo method of this class is used
at translation time to obtain information on each variable that will be created at
request time when this action is executed. The method is passed a TagData
instance that contains the translation-time attribute values.
Validation
The TLD file contains several pieces of information that is used to do syntactic
validation at translation-time. It also contains two extensible validation mecha-
nisms: a TagLibraryValidator class can be used to validate a complete JSP page, and a
TagExtraInfo class can be used to validate a specific action. In some cases, additional
request-time validation will be done dynamically within the methods in the Tag
instance. If an error is discovered, an instance of JspTagException can be thrown. If
uncaught, this object will invoke the errorpage mechanism of JSP.
The TagLibraryValidator is an addition to the JSP 1.2 specification and is very
open ended, being strictly more powerful than the TagExtraInfo mechanism. A
JSP page is presented via the PageData object, which abstracts the XML view of
the JSP page.
A PageData instance will provides an InputStream (read-only) on the page.
Later specifications may add other views on the page (DOM, SAX, JDOM are all
candidates), for now these views can be generated from the InputStream and
perhaps can be cached for improved performance (recall the view of the page is
just read-only).
As of JSP 2.0, the JSP container must support a jsp:id attribute to provide
higher quality validation errors. The container will track the JSP pages as passed
to the container, and will assign to each element a unique “id”, which is passed as
the value of the jsp:id attribute. Each XML element in the XML view will be
extended with this attribute. The TagLibraryValidator can use the attribute in one
or more ValidationMessage objects. The container then, in turn, can use these
values to provide more precise information on the location of an error.
The prefix for the id attribute need not be “jsp” but it must map to the
namespace http://java.sun.com/JSP/Page. In the case where the user has redefined
the jsp prefix, an alternative prefix must be used by the container.
Validation Details
In detail, validation is done as follows:
First, the JSP page is parsed using the information in the TLD. At this stage
valid mandatory and optional attributes are checked.
Second, for each unique tag library in the page as determined by the tag
library URI, and in the lexical order in which they appear, their associated
validator class (if any) is invoked. This involves several substeps.
The first substep is to obtain an initialized validator instance by either:
•construct a new instance and invoke setInitParameters() on it, or
•obtain an existing instance that is not being used, invoke release() on it, and
then invoke setInitParameters() on it, or
•locate an existing instance that is not being used on which the desired set-
InitParameters() has already been invoked
The class name is as indicated in the <validator-class> element, and the Map
passed through setInitParameters() is as described in the <init-params> element. All
TagLibraryValidator classes are supposed to keep their initParameters until new
ones are set, or until release() is invoked on them.
The second substep is to perform the actual validation. This is done by
invoking the validate() method with a prefix, uri, and PageData that correspond to
the taglib directive instance being validated and the PageData representing the
page. In the case where a single URI is mapped to more than one prefix, the prefix
of the first URI must be used.
The last substep is to invoke the release() method on the validator tag when it
is no longer needed. This method releases all resources.
Finally, after checking all the tag library validator classes, the TagExtraInfo
classes for all tags will be consulted by invoking their validate method. The order
of invocation of this methods is undefined.
JSP.13.9.1 TagLibraryInfo
Syntax
public abstract class TagLibraryInfo
Description
Translation-time information associated with a taglib directive, and its underlying
TLD file. Most of the information is directly from the TLD, except for the prefix
and the uri values used in the taglib directive
JSP.13.9.1.1 Fields
protected FunctionInfo[] functions
An array describing the functions that are defined in this tag library.
Since: 2.0
protected java.lang.String info
Information (documentation) for this TLD.
protected java.lang.String jspversion
The version of the JSP specification this tag library is written to.
protected java.lang.String prefix
The prefix assigned to this taglib from the taglib directive.
protected java.lang.String shortname
The preferred short name (prefix) as indicated in the TLD.
protected TagFileInfo[] tagFiles
An array describing the tag files that are defined in this tag library.
Since: 2.0
protected TagInfo[] tags
An array describing the tags that are defined in this tag library.
protected java.lang.String tlibversion
The version of the tag library.
protected java.lang.String uri
The value of the uri attribute from the taglib directive for this library.
protected java.lang.String urn
The “reliable” URN indicated in the TLD.
JSP.13.9.1.2 Constructors
protected TagLibraryInfo(java.lang.String prefix, java.lang.String uri)
Constructor. This will invoke the constructors for TagInfo, and TagAttribute-
Info after parsing the TLD file.
Parameters:
prefix - the prefix actually used by the taglib directive
uri - the URI actually used by the taglib directive
JSP.13.9.1.3 Methods
public FunctionInfo getFunction(java.lang.String name)
Get the FunctionInfo for a given function name, looking through all the func-
tions in this tag library.
Parameters:
name - The name (no prefix) of the function
Returns: the FunctionInfo for the function with the given name, or null if
no such function exists
Since: 2.0
public FunctionInfo[] getFunctions()
An array describing the functions that are defined in this tag library.
Returns: the functions defined in this tag library, or a zero length array if
the tag library defines no functions.
Since: 2.0
public java.lang.String getInfoString()
Information (documentation) for this TLD.
Returns: the info string for this tag lib
public java.lang.String getPrefixString()
The prefix assigned to this taglib from the taglib directive
Returns: the prefix assigned to this taglib from the taglib directive
public java.lang.String getReliableURN()
The “reliable” URN indicated in the TLD (the uri element). This may be used
by authoring tools as a global identifier to use when creating a taglib directive
for this library.
Returns: a reliable URN to a TLD like this
public java.lang.String getRequiredVersion()
JSP.13.9.2 TagInfo
Syntax
public class TagInfo
Description
Tag information for a tag in a Tag Library; This class is instantiated from the Tag
Library Descriptor file (TLD) and is available only at translation time.
JSP.13.9.2.1 Fields
public static final java.lang.String BODY_CONTENT_EMPTY
Static constant for getBodyContent() when it is empty.
public static final java.lang.String BODY_CONTENT_JSP
Static constant for getBodyContent() when it is JSP.
public static final java.lang.String BODY_CONTENT_SCRIPTLESS
Static constant for getBodyContent() when it is scriptless.
Since: 2.0
public static final java.lang.String BODY_CONTENT_TAG_DEPENDENT
Static constant for getBodyContent() when it is Tag dependent.
JSP.13.9.2.2 Constructors
public TagInfo(java.lang.String tagName, java.lang.String tagClassName,
java.lang.String bodycontent, java.lang.String infoString,
TagLibraryInfo taglib, TagExtraInfo tagExtraInfo,
TagAttributeInfo[] attributeInfo)
Constructor for TagInfo from data in the JSP 1.1 format for TLD. This class
is to be instantiated only from the TagLibrary code under request from some
JSP code that is parsing a TLD (Tag Library Descriptor). Note that, since
TagLibibraryInfo reflects both TLD information and taglib directive informa-
tion, a TagInfo instance is dependent on a taglib directive. This is probably a
design error, which may be fixed in the future.
Parameters:
tagName - The name of this tag
tagClassName - The name of the tag handler class
JSP code that is parsing a TLD (Tag Library Descriptor). Note that, since
TagLibibraryInfo reflects both TLD information and taglib directive informa-
tion, a TagInfo instance is dependent on a taglib directive. This is probably a
design error, which may be fixed in the future.
Parameters:
tagName - The name of this tag
tagClassName - The name of the tag handler class
bodycontent - Information on the body content of these tags
infoString - The (optional) string information for this tag
taglib - The instance of the tag library that contains us.
tagExtraInfo - The instance providing extra Tag info. May be null
attributeInfo - An array of AttributeInfo data from descriptor. May be null;
displayName - A short name to be displayed by tools
smallIcon - Path to a small icon to be displayed by tools
largeIcon - Path to a large icon to be displayed by tools
tvi - An array of a TagVariableInfo (or null)
dynamicAttributes - True if supports dynamic attributes
Since: 2.0
JSP.13.9.2.3 Methods
public TagAttributeInfo[] getAttributes()
Attribute information (in the TLD) on this tag. The return is an array describ-
ing the attributes of this tag, as indicated in the TLD.
Returns: The array of TagAttributeInfo for this tag, or a zero-length array if
the tag has no attributes.
public java.lang.String getBodyContent()
The bodycontent information for this tag. If the bodycontent is not defined
for this tag, the default of JSP will be returned.
Returns: the body content string.
public java.lang.String getDisplayName()
Get the displayName.
Returns: A short name to be displayed by tools, or null if not defined
public java.lang.String getInfoString()
JSP.13.9.3 TagFileInfo
Syntax
public class TagFileInfo
Description
Tag information for a tag file in a Tag Library; This class is instantiated from the
Tag Library Descriptor file (TLD) and is available only at translation time.
Since: 2.0
JSP.13.9.3.1 Constructors
public TagFileInfo(java.lang.String name, java.lang.String path, TagInfo tagInfo)
Constructor for TagFileInfo from data in the JSP 2.0 format for TLD. This
class is to be instantiated only from the TagLibrary code under request from
some JSP code that is parsing a TLD (Tag Library Descriptor). Note that,
since TagLibibraryInfo reflects both TLD information and taglib directive
information, a TagFileInfo instance is dependent on a taglib directive. This is
probably a design error, which may be fixed in the future.
Parameters:
name - The unique action name of this tag
path - Where to find the .tag file implementing this action, relative to the
location of the TLD file.
tagInfo - The detailed information about this tag, as parsed from the directives
in the tag file.
JSP.13.9.3.2 Methods
public java.lang.String getName()
The unique action name of this tag.
Returns: The (short) name of the tag.
public java.lang.String getPath()
Where to find the .tag file implementing this action.
Returns: The path of the tag file, relative to the TLD, or “.” if the tag file
was defined in an implicit tag file.
public TagInfo getTagInfo()
Returns information about this tag, parsed from the directives in the tag file.
Returns: a TagInfo object containing information about this tag
JSP.13.9.4 TagAttributeInfo
Syntax
public class TagAttributeInfo
Description
Information on the attributes of a Tag, available at translation time. This class is
instantiated from the Tag Library Descriptor file (TLD).
Only the information needed to generate code is included here. Other information
like SCHEMA for validation belongs elsewhere.
JSP.13.9.4.1 Fields
public static final java.lang.String ID
“id” is wired in to be ID. There is no real benefit in having it be something
else IDREFs are not handled any differently.
JSP.13.9.4.2 Constructors
public TagAttributeInfo(java.lang.String name, boolean required,
java.lang.String type, boolean reqTime)
Constructor for TagAttributeInfo. This class is to be instantiated only from
the TagLibrary code under request from some JSP code that is parsing a TLD
(Tag Library Descriptor).
Parameters:
name - The name of the attribute.
required - If this attribute is required in tag instances.
type - The name of the type of the attribute.
reqTime - Whether this attribute holds a request-time Attribute.
public TagAttributeInfo(java.lang.String name, boolean required,
java.lang.String type, boolean reqTime, boolean fragment)
JSP 2.0 Constructor for TagAttributeInfo. This class is to be instantiated only
from the TagLibrary code under request from some JSP code that is parsing a
TLD (Tag Library Descriptor).
Parameters:
name - The name of the attribute.
required - If this attribute is required in tag instances.
type - The name of the type of the attribute.
JSP.13.9.4.3 Methods
public boolean canBeRequestTime()
Whether this attribute can hold a request-time value.
Returns: if the attribute can hold a request-time value.
public static TagAttributeInfo getIdAttribute(TagAttributeInfo[] a)
Convenience static method that goes through an array of TagAttributeInfo
objects and looks for “id”.
Parameters:
a - An array of TagAttributeInfo
Returns: The TagAttributeInfo reference with name “id”
public java.lang.String getName()
The name of this attribute.
Returns: the name of the attribute
public java.lang.String getTypeName()
The type (as a String) of this attribute.
Returns: the type of the attribute
public boolean isFragment()
Whether this attribute is of type JspFragment.
Returns: if the attribute is of type JspFragment
Since: 2.0
public boolean isRequired()
Whether this attribute is required.
Returns: if the attribute is required.
public java.lang.String toString()
Returns a String representation of this TagAttributeInfo, suitable for debug-
ging purposes.
Overrides: java.lang.Object.toString() in class java.lang.Object
Returns: a String representation of this TagAttributeInfo
JSP.13.9.5 PageData
Syntax
public abstract class PageData
Description
Translation-time information on a JSP page. The information corresponds to the
XML view of the JSP page.
Objects of this type are generated by the JSP translator, e.g. when being pased to
a TagLibraryValidator instance.
JSP.13.9.5.1 Constructors
public PageData()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
JSP.13.9.5.2 Methods
public abstract java.io.InputStream getInputStream()
Returns an input stream on the XML view of a JSP page. The stream is
encoded in UTF-8. Recall tht the XML view of a JSP page has the include
directives expanded.
Returns: An input stream on the document.
JSP.13.9.6 TagLibraryValidator
Syntax
public abstract class TagLibraryValidator
Description
Translation-time validator class for a JSP page. A validator operates on the XML
view associated with the JSP page.
The TLD file associates a TagLibraryValidator class and some init arguments
with a tag library.
The JSP container is reponsible for locating an appropriate instance of the appro-
priate subclass by
•new a fresh instance, or reuse an available one
•invoke the setInitParams(Map) method on the instance
JSP.13.9.6.1 Constructors
public TagLibraryValidator()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
JSP.13.9.6.2 Methods
public java.util.Map getInitParameters()
Get the init parameters data as an immutable Map. Parameter names are keys,
and parameter values are the values.
Returns: The init parameters as an immutable map.
public void release()
Release any data kept by this instance for validation purposes.
public void setInitParameters(java.util.Map map)
Set the init data in the TLD for this validator. Parameter names are keys, and
parameter values are the values.
Parameters:
map - A Map describing the init parameters
public ValidationMessage[] validate(java.lang.String prefix, java.lang.String uri,
PageData page)
Validate a JSP page. This will get invoked once per unique tag library URI in
the XML view. This method will return null if the page is valid; otherwise the
method should return an array of ValidationMessage objects. An array of
length zero is also interpreted as no errors.
Parameters:
prefix - the first prefix with which the tag library is associated, in the XML
view. Note that some tags may use a different prefix if the namespace is
redefined.
uri - the tag library’s unique identifier
page - the JspData page object
Returns: A null object, or zero length array if no errors, an array of
ValidationMessages otherwise.
JSP.13.9.7 ValidationMessage
Syntax
public class ValidationMessage
Description
A validation message from either TagLibraryValidator or TagExtraInfo.
As of JSP 2.0, a JSP container must support a jsp:id attribute to provide higher
quality validation errors. The container will track the JSP pages as passed to the
container, and will assign to each element a unique “id”, which is passed as the
value of the jsp:id attribute. Each XML element in the XML view available will
be extended with this attribute. The TagLibraryValidator can then use the attribute
in one or more ValidationMessage objects. The container then, in turn, can use
these values to provide more precise information on the location of an error.
The actual prefix of the id attribute may or may not be jsp but it will always map
to the namespace http://java.sun.com/JSP/Page. A TagLibraryValidator imple-
mentation must rely on the uri, not the prefix, of the id attribute.
JSP.13.9.7.1 Constructors
public ValidationMessage(java.lang.String id, java.lang.String message)
Create a ValidationMessage. The message String should be non-null. The
value of id may be null, if the message is not specific to any XML element, or
if no jsp:id attributes were passed on. If non-null, the value of id must be the
value of a jsp:id attribute for the PageData passed into the validate() method.
Parameters:
id - Either null, or the value of a jsp:id attribute.
message - A localized validation message.
JSP.13.9.7.2 Methods
public java.lang.String getId()
Get the jsp:id. Null means that there is no information available.
Returns: The jsp:id information.
public java.lang.String getMessage()
Get the localized validation message.
Returns: A validation message
JSP.13.9.8 TagExtraInfo
Syntax
public abstract class TagExtraInfo
Description
Optional class provided by the tag library author to describe additional transla-
tion-time information not described in the TLD. The TagExtraInfo class is men-
tioned in the Tag Library Descriptor file (TLD).
This class can be used:
•to indicate that the tag defines scripting variables
•to perform translation-time validation of the tag attributes.
It is the responsibility of the JSP translator that the initial value to be returned by
calls to getTagInfo() corresponds to a TagInfo object for the tag being translated.
If an explicit call to setTagInfo() is done, then the object passed will be returned
in subsequent calls to getTagInfo().
The only way to affect the value returned by getTagInfo() is through a setTag-
Info() call, and thus, TagExtraInfo.setTagInfo() is to be called by the JSP transla-
tor, with a TagInfo object that corresponds to the tag being translated. The call
should happen before any invocation on validate() and before any invocation on
getVariableInfo().
NOTE: It is a (translation time) error for a tag definition in a TLD with one or
more variable subelements to have an associated TagExtraInfo implementation
that returns a VariableInfo array with one or more elements from a call to
getVariableInfo().
JSP.13.9.8.1 Constructors
public TagExtraInfo()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
JSP.13.9.8.2 Methods
public final TagInfo getTagInfo()
Get the TagInfo for this class.
Returns: the taginfo instance this instance is extending
public VariableInfo[] getVariableInfo(TagData data)
information on scripting variables defined by the tag associated with this Tag-
ExtraInfo instance. Request-time attributes are indicated as such in the Tag-
Data parameter.
Parameters:
data - The TagData instance.
Returns: An array of VariableInfo data, or null or a zero length array if no
scripting variables are to be defined.
public boolean isValid(TagData data)
Translation-time validation of the attributes. Request-time attributes are indi-
cated as such in the TagData parameter. Note that the preferred way to do val-
idation is with the validate() method, since it can return more detailed
information.
Parameters:
data - The TagData instance.
Returns: Whether this tag instance is valid.
See Also: public ValidationMessage[] validate(TagData data)
public final void setTagInfo(TagInfo tagInfo)
JSP.13.9.9 TagData
Syntax
public class TagData implements java.lang.Cloneable
Description
The (translation-time only) attribute/value information for a tag instance.
JSP.13.9.9.1 Fields
public static final java.lang.Object REQUEST_TIME_VALUE
Distinguished value for an attribute to indicate its value is a request-time
expression (which is not yet available because TagData instances are used at
translation-time).
JSP.13.9.9.2 Constructors
public TagData(java.util.Hashtable attrs)
Constructor for a TagData. If you already have the attributes in a hashtable,
use this constructor.
Parameters:
attrs - A hashtable to get the values from.
public TagData(java.lang.Object[][] atts)
Constructor for TagData.
A typical constructor may be
static final Object[][] att = {{“connection”, “conn0”},
{“id”, “query0”}};
static final TagData td = new TagData(att);
All values must be Strings except for those holding the distinguished object
REQUEST_TIME_VALUE.
Parameters:
atts - the static attribute and values. May be null.
JSP.13.9.9.3 Methods
public java.lang.Object getAttribute(java.lang.String attName)
The value of the attribute. If a static value is specified for an attribute that
accepts a request-time attribute expression then that static value is returned,
even if the value is provided in the body of a action. The distinguished object
REQUEST_TIME_VALUE is only returned if the value is specified as a
request-time attribute expression or via the <jsp:attribute> action with a body
that contains dynamic content (scriptlets, scripting expressions, EL expres-
sions, standard actions, or custom actions). Returns null if the attribute is not
set.
Parameters:
attName - the name of the attribute
Returns: the attribute’s value
public java.util.Enumeration getAttributes()
Enumerates the attributes.
Returns: An enumeration of the attributes in a TagData
public java.lang.String getAttributeString(java.lang.String attName)
Get the value for a given attribute.
Parameters:
JSP.13.9.10 VariableInfo
Syntax
public class VariableInfo
Description
Information on the scripting variables that are created/modified by a tag (at run-
time). This information is provided by TagExtraInfo classes and it is used by the
translation phase of JSP.
Scripting variables generated by a custom action have an associated scope of
either AT_BEGIN, NESTED, or AT_END.
The class name (VariableInfo.getClassName) in the returned objects is used to
determine the types of the scripting variables. Note that because scripting vari-
ables are assigned their values from scoped attributes which cannot be of primi-
tive types, “boxed” types such as java.lang.Integer must be used instead of
primitives.
The class name may be a Fully Qualified Class Name, or a short class name.
If a Fully Qualified Class Name is provided, it should refer to a class that should
be in the CLASSPATH for the Web Application (see Servlet 2.4 specification -
essentially it is WEB-INF/lib and WEB-INF/classes). Failure to be so will lead to
a translation-time error.
If a short class name is given in the VariableInfo objects, then the class name must
be that of a public class in the context of the import directives of the page where
the custom action appears. The class must also be in the CLASSPATH for the
Web Application (see Servlet 2.4 specification - essentially it is WEB-INF/lib and
WEB-INF/classes). Failure to be so will lead to a translation-time error.
Usage Comments
Frequently a fully qualified class name will refer to a class that is known to the tag
library and thus, delivered in the same JAR file as the tag handlers. In most other
remaining cases it will refer to a class that is in the platform on which the JSP
processor is built (like J2EE). Using fully qualified class names in this manner
makes the usage relatively resistant to configuration errors.
A short name is usually generated by the tag library based on some attributes
passed through from the custom action user (the author), and it is thus less robust:
for instance a missing import directive in the referring JSP page will lead to an
invalid short name class and a translation error.
Synchronization Protocol
The result of the invocation on getVariableInfo is an array of VariableInfo objects.
Each such object describes a scripting variable by providing its name, its type,
whether the variable is new or not, and what its scope is. Scope is best described
through a picture:
The scope value for a variable implies what methods may affect its value and thus
where synchronization is needed as illustrated by the table below. Note: the syn-
chronization of the variable(s) will occur after the respective method has been
called.
Simpl AT_BEGIN,
eTag AT_END
1
Called after doStartTag() if EVAL_BODY_INCLUDE is returned, or after doInit-
Body() otherwise.
JSP.13.9.10.1 Fields
public static final int AT_BEGIN
Scope information that scripting variable is visible after start tag.
public static final int AT_END
Scope information that scripting variable is visible after end tag.
public static final int NESTED
Scope information that scripting variable is visible only within the start/end
tags.
JSP.13.9.10.2 Constructors
public VariableInfo(java.lang.String varName, java.lang.String className,
boolean declare, int scope)
Constructor These objects can be created (at translation time) by the Tag-
ExtraInfo instances.
Parameters:
varName - The name of the scripting variable
className - The type of this variable
declare - If true, it is a new variable (in some languages this will require a
declaration)
scope - Indication on the lexical scope of the variable
JSP.13.9.10.3 Methods
public java.lang.String getClassName()
Returns the type of this variable.
Returns: the type of this variable
public boolean getDeclare()
Returns whether this is a new variable. If so, in some languages this will
require a declaration.
Returns: whether this is a new variable.
public int getScope()
Returns the lexical scope of the variable.
Returns: the lexical scope of the variable, either AT_BEGIN, AT_END, or
NESTED.
See Also: public static final int AT_BEGIN, public static final int AT_END,
public static final int NESTED
public java.lang.String getVarName()
Returns the name of the scripting variable.
Returns: the name of the scripting variable
JSP.13.9.11 TagVariableInfo
Syntax
public class TagVariableInfo
Description
Variable information for a tag in a Tag Library; This class is instantiated from the
Tag Library Descriptor file (TLD) and is available only at translation time. This
object should be immutable. This information is only available in JSP 1.2 format
TLDs or above.
JSP.13.9.11.1 Constructors
public TagVariableInfo(java.lang.String nameGiven,
java.lang.String nameFromAttribute, java.lang.String className,
boolean declare, int scope)
Constructor for TagVariableInfo.
Parameters:
nameGiven - value of <name-given>
nameFromAttribute - value of <name-from-attribute>
className - value of <variable-class>
declare - value of <declare>
scope - value of <scope>
JSP.13.9.11.2 Methods
public java.lang.String getClassName()
The body of the <variable-class> element.
Returns: The name of the class of the variable or ’java.lang.String’ if not
defined in the TLD.
public boolean getDeclare()
The body of the <declare> element.
Returns: Whether the variable is to be declared or not. If not defined in the
TLD, ’true’ will be returned.
public java.lang.String getNameFromAttribute()
The body of the <name-from-attribute> element. This is the name of an
attribute whose (translation-time) value will give the name of the variable.
One of <name-given> or <name-from-attribute> is required.
Returns: The attribute whose value defines the variable name
public java.lang.String getNameGiven()
The body of the <name-given> element.
Returns: The variable name as a constant
JavaServer Pages 2.0 Specification
2-124 TAG EXTENSION API
JSP.13.9.12 FunctionInfo
Syntax
public class FunctionInfo
Description
Information for a function in a Tag Library. This class is instantiated from the Tag
Library Descriptor file (TLD) and is available only at translation time.
Since: 2.0
JSP.13.9.12.1 Constructors
public FunctionInfo(java.lang.String name, java.lang.String klass,
java.lang.String signature)
Constructor for FunctionInfo.
Parameters:
name - The name of the function
klass - The class of the function
signature - The signature of the function
JSP.13.9.12.2 Methods
public java.lang.String getFunctionClass()
The class of the function.
Returns: The class of the function
public java.lang.String getFunctionSignature()
The signature of the function.
Returns: The signature of the function
public java.lang.String getName()
The name of the function.
2-127
2-128 EXPRESSION LANGUAGE API
JSP.14.1.1 ExpressionEvaluator
Syntax
public abstract class ExpressionEvaluator
Description
The abstract base class for an expression-language evaluator. Classes that imple-
ment an expression language expose their functionality via this abstract class.
An instance of the ExpressionEvaluator can be obtained via the JspContext /
PageContext
The parseExpression() and evaluate() methods must be thread-safe. That is, mul-
tiple threads may call these methods on the same ExpressionEvaluator object
simultaneously. Implementations should synchronize access if they depend on
transient state. Implementations should not, however, assume that only one
object of each ExpressionEvaluator type will be instantiated; global caching
should therefore be static.
Only a single EL expression, starting with ’${’ and ending with ’}’, can be parsed
or evaluated at a time. EL expressions cannot be mixed with static text. For exam-
ple, attempting to parse or evaluate “abc${1+1}def${1+1}ghi” or even
“${1+1}${1+1}” will cause an ELException to be thrown.
The following are examples of syntactically legal EL expressions:
•${person.lastName}
•${8 * 8}
•${my:reverse('hello')}
Since: 2.0
JSP.14.1.1.1 Constructors
public ExpressionEvaluator()
JSP.14.1.1.2 Methods
public abstract java.lang.Object evaluate(java.lang.String expression,
java.lang.Class expectedType, VariableResolver vResolver,
FunctionMapper fMapper)
Evaluates an expression. This method may perform some syntactic validation
and, if so, it should raise an ELParseException error if it encounters syntactic
errors. EL evaluation errors should cause an ELException to be raised.
Parameters:
expression - The expression to be evaluated.
expectedType - The expected type of the result of the evaluation
vResolver - A VariableResolver instance that can be used at runtime to
resolve the name of implicit objects into Objects.
fMapper - A FunctionMapper to resolve functions found in the expression. It
can be null, in which case no functions are supported for this invocation.
Returns: The result of the expression evaluation.
Throws:
ELException - Thrown if the expression evaluation failed.
public abstract Expression parseExpression(java.lang.String expression,
java.lang.Class expectedType, FunctionMapper fMapper)
Prepare an expression for later evaluation. This method should perform syn-
tactic validation of the expression; if in doing so it detects errors, it should
raise an ELParseException.
Parameters:
expression - The expression to be evaluated.
expectedType - The expected type of the result of the evaluation
fMapper - A FunctionMapper to resolve functions found in the expression. It
can be null, in which case no functions are supported for this invocation. The
ExpressionEvaluator must not hold on to the FunctionMapper reference after
returning from parseExpression(). The Expression object returned must
invoke the same functions regardless of whether the mappings in the
provided FunctionMapper instance change between calling
ExpressionEvaluator.parseExpression() and Expression.evaluate().
Returns: The Expression object encapsulating the arguments.
Throws:
ELException - Thrown if parsing errors were found.
JSP.14.1.2 Expression
Syntax
public abstract class Expression
Description
The abstract class for a prepared expression.
Since: 2.0
JSP.14.1.2.1 Constructors
public Expression()
JSP.14.1.2.2 Methods
public abstract java.lang.Object evaluate(VariableResolver vResolver)
Evaluates an expression that was previously prepared. In some implementa-
tions preparing an expression involves full syntactic validation, but others
may not do so. Evaluating the expression may raise an ELParseException as
well as other ELExceptions due to run-time evaluation.
Parameters:
vResolver - A VariableResolver instance that can be used at runtime to
resolve the name of implicit objects into Objects.
Returns: The result of the expression evaluation.
Throws:
ELException - Thrown if the expression evaluation failed.
JSP.14.1.3 VariableResolver
Syntax
public interface VariableResolver
Description
This class is used to customize the way an ExpressionEvaluator resolves variable
references at evaluation time. For example, instances of this class can implement
their own variable lookup mechanisms, or introduce the notion of “implicit vari-
ables” which override any other variables. An instance of this class should be
passed when evaluating an expression.
An instance of this class includes the context against which resolution will hap-
pen
Since: 2.0
JSP.14.1.3.1 Methods
public java.lang.Object resolveVariable(java.lang.String pName)
Resolves the specified variable. Returns null if the variable is not found.
Parameters:
pName - the name of the variable to resolve
Returns: the result of the variable resolution
Throws:
ELException - if a failure occurred while trying to resolve the given variable
JSP.14.1.4 FunctionMapper
Syntax
public interface FunctionMapper
Description
The interface to a map between EL function names and methods.
Classes implementing this interface may, for instance, consult tag library infor-
mation to resolve the map.
Since: 2.0
JSP.14.1.4.1 Methods
public java.lang.reflect.Method resolveFunction(java.lang.String prefix,
java.lang.String localName)
JSP.14.2 Exceptions
JSP.14.2.1 ELException
Syntax
public class ELException extends java.lang.Exception
Description
Represents any of the exception conditions that arise during the operation evalua-
tion of the evaluator.
Since: 2.0
JSP.14.2.1.1 Constructors
public ELException()
Creates an ELException with no detail message.
JSP.14.2.1.2 Methods
public java.lang.Throwable getRootCause()
Returns the root cause.
Returns: the root cause of this exception
JSP.14.2.2 ELParseException
Syntax
public class ELParseException extends ELException
Description
Represents a parsing error encountered while parsing an EL expression.
Since: 2.0
JSP.14.2.2.1 Constructors
public ELParseException()
Creates an ELParseException with no detail message.
Below is a non-normative code fragment outlining how the APIs can be used.
// Get an instance of an ExpressionEvaluator
ExpressionEvaluator ee = myJspContext.getExpressionEvaluator();
VariableResolver vr = myJspContext.getVariableResolver();
FunctionMapper fm; // we don't have a portable implementation yet
// Example of compiling an expression. See [ISSUE-2]
// Errors detected this way may have higher quality than those
// found with a simple validate() invocation.
ExpressionCompilation ce;
try {
ce = ee.prepareExpression(expr,
targetClass,
fm,
null // no prefixes
);
} catch (ELParseException e) {
log (e.getMessage());
}
try {
ce.evaluate(vr);
} catch (ElException e) {
log (e);
}
This appendix shows two simple examples of packaging a JSP page into a
WAR for delivery into a Web container. In the first example, the JSP page is deliv-
ered in source form. This is likely to be the most common example. In the second
example the JSP page is compiled into a servlet that uses only Servlet 2.4 and JSP
2.0 API calls; the servlet is then packaged into a WAR with a deployment descriptor
such that it looks as the original JSP page to any client.
This appendix is non normative. Actually, strictly speaking, the appendix
relates more to the Servlet 2.4 capabilities than to the JSP 2.0 capabilities. The
appendix is included here as this is a feature that JSP page authors and JSP page
authoring tools are interested in.
The JSP page can be packaged into a WAR file by just placing it at location /
HelloWorld.jsp the default JSP page extension mapping will pick it up. The web.xml
is trivial:
<!DOCTYPE webapp
SYSTEM "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<webapp>
<session-config>
<session-timeout> 1 </session-timeout>
</session-config>
</webapp>
As an alternative, we will show how one can compile the JSP page into a servlet
class to run in a JSP container.
The JSP page is compiled into a servlet with some implementation dependent
name com.acme._jsp_HelloWorld_XXX_Impl. The servlet code only depends on the
JSP 2.0 and Servlet 2.4 APIs, as follows:
package com.acme;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
{
Object page= this;
HttpSessionsession= request.getSession();
ServletConfigconfig= getServletConfig();
ServletContextapplication = config.getServletContext();
PageContextpageContext
= _factory.getPageContext(this,
request,
response,
(String)NULL,
true,
JspWriter.DEFAULT_BUFFER,
true
);
JspWriterout= pageContext.getOut();
// page context creates initial JspWriter "out"
try {
out.println("<p>");
out.println("Hello World");
out.println("</p>");
} catch (Exception e) {
pageContext.handlePageException(e);
} finally {
_factory.releasePageContext(pageContext);
}
}
}
The servlet is made to look as a JSP page with the following web.xml:
<!DOCTYPE webapp
SYSTEM "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<webapp>
<servlet>
<servlet-name> HelloWorld </servlet-name>
<servlet-class>com.acme._jsp_HelloWorld_XXX_Impl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> HelloWorld </servlet-name>
<url-pattern> /HelloWorld.jsp </url-pattern>
</servlet-mapping>
<session-config>
<session-timeout> 1 </session-timeout>
</session-config>
</webapp>
/WEB-INF/web.xml
/WEB-INF/classes/com/acme/_jsp_HelloWorld_XXX_Impl.class
Note that if the servlet class generated for the JSP page had depended on some
support classes, they would have to be included in the WAR.
This appendix describes the JSP elements of the Servlet 2.4 Web Application
Deployment Descriptor, which is described using XML Schema. The Servlet 2.4
deployment descriptor schema includes the definitions that appear in this Appendix.
This is the same XML Schema as http://java.sun.com/xml/ns/j2ee/jsp_2_0.xsd,
except for some formatting changes to extract comments and make them more
readable.
<xsd:annotation>
<xsd:documentation>
This is the XML Schema for the JSP 2.0 deployment descriptor
types. The JSP 2.0 schema contains all the special
structures and datatypes that are necessary to use JSP files
from a web application.
</xsd:documentation>
</xsd:annotation>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:include schemaLocation="j2ee_1_4.xsd"/>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="taglib"
type="j2ee:taglibType"
minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="jsp-property-group"
type="j2ee:jsp-property-groupType"
minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:restriction base="j2ee:pathType"/>
</xsd:simpleContent>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:group ref="j2ee:descriptionGroup"/>
<xsd:element name="url-pattern"
type="j2ee:url-patternType"
maxOccurs="unbounded"/>
<xsd:element name="el-ignored"
type="j2ee:true-falseType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="page-encoding"
type="j2ee:string"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="scripting-invalid"
type="j2ee:true-falseType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="is-xml"
type="j2ee:true-falseType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="include-prelude"
type="j2ee:pathType"
minOccurs="0"
maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="include-coda"
type="j2ee:pathType"
minOccurs="0"
maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="taglib-uri"
type="j2ee:string">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="taglib-location"
type="j2ee:pathType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
</xsd:schema>
T his appendix includes the XML Schema and DTD files for tag library
descriptors using each version of the JSP specification (from JSP 1.1 to current). All
JSP 2.0 containers are required to be able to parse and accept all TLD formats
described in this appendix. The formats are listed in order from most recent to least
recent.
taglib
description*
description* small-icon?
display-name* large-icon?
icon*
icon*
description*
tlib-version
tlib-version
validator-class
short-name
short-name
init-param* description*
uri?
uri?
param-name
validator?
validator?
param-value
listener*
listener* See Below...
tag*
tag* See Below...
tag-file*
tag-file* See Below...
function
function* See Below...
taglib-extension* extension-element+
listener*
description*
display-name*
small-icon?
icon*
large-icon?
listener-class
tag*
description* small-icon?
display-name* large-icon?
icon*
description*
name
name-given |
tag-class name-from-attribute
tei-class? variable-class?
body-content declare?
variable* scope?
description*
attribute*
name
required?
tag-extension* extension-element+
tag-file*
description*
display-name*
small-icon?
icon*
large-icon?
name
path
example?
tag-extension* extension-element+
function*
description*
display-name*
small-icon?
icon*
large-icon?
name
function-class
function-signature
example?
function-extension* extension-element+
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="2.0">
<xsd:annotation>
<xsd:documentation>
http://java.sun.com/xml/ns/j2ee
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="..."
version="2.0">
...
</taglib>
http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd
</xsd:documentation>
</xsd:annotation>
<xsd:include schemaLocation="j2ee_1_4.xsd"/>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:unique name="tag-name-uniqueness">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:selector xpath="j2ee:tag|j2ee:tag-file"/>
<xsd:field xpath="j2ee:name"/>
</xsd:unique>
<xsd:unique name="function-name-uniqueness">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:selector xpath="j2ee:function"/>
<xsd:field xpath="j2ee:name"/>
</xsd:unique>
</xsd:element>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:restriction base="j2ee:string">
<xsd:enumeration value="tagdependent"/>
<xsd:enumeration value="JSP"/>
<xsd:enumeration value="empty"/>
<xsd:enumeration value="scriptless"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:group ref="j2ee:descriptionGroup"/>
<xsd:element name="name"
type="j2ee:tld-canonical-nameType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="function-class"
type="j2ee:fully-qualified-classType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="function-signature"
type="j2ee:string">
<xsd:annotation>
<xsd:documentation>
Where:
Example:
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="example"
type="j2ee:xsdStringType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="function-extension"
type="j2ee:tld-extensionType"
minOccurs="0"
maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Function extensions are for tool use only and must not affect
the behavior of a container.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
consumption
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:group ref="j2ee:descriptionGroup"/>
<xsd:element name="name"
type="j2ee:tld-canonical-nameType"/>
<xsd:element name="path"
type="j2ee:pathType"/>
<xsd:element name="example"
type="j2ee:xsdStringType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="tag-extension"
type="j2ee:tld-extensionType"
minOccurs="0"
maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Tag extensions are for tool use only and must not affect
the behavior of a container.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
The tag defines a unique tag in this tag library. It has one
attribute, id.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:group ref="j2ee:descriptionGroup"/>
<xsd:element name="name"
type="j2ee:tld-canonical-nameType"/>
<xsd:element name="tag-class"
type="j2ee:fully-qualified-classType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="tei-class"
type="j2ee:fully-qualified-classType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="body-content"
type="j2ee:body-contentType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="variable"
type="j2ee:variableType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="attribute"
type="j2ee:tld-attributeType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="dynamic-attributes"
type="j2ee:generic-booleanType"
minOccurs="0"/>
<xsd:element name="example"
type="j2ee:xsdStringType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="tag-extension"
type="j2ee:tld-extensionType"
minOccurs="0"
maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Tag extensions are for tool use only and must not affect
the behavior of a container.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="description"
type="j2ee:descriptionType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="name"
type="j2ee:java-identifierType"/>
<xsd:element name="required"
type="j2ee:generic-booleanType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:choice>
<xsd:sequence>
<xsd:element name="rtexprvalue"
type="j2ee:generic-booleanType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="type"
type="j2ee:fully-qualified-classType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:element name="fragment"
type="j2ee:generic-booleanType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:choice>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:restriction base="j2ee:xsdNMTOKENType"/>
</xsd:simpleContent>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="extension-element"
type="j2ee:extensibleType"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="namespace"
use="required"
type="xsd:anyURI"/>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:group ref="j2ee:descriptionGroup"/>
<xsd:element name="tlib-version"
type="j2ee:dewey-versionType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="short-name"
type="j2ee:tld-canonical-nameType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="uri"
type="j2ee:xsdAnyURIType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="validator"
type="j2ee:validatorType"
minOccurs="0">
</xsd:element>
<xsd:element name="listener"
type="j2ee:listenerType"
minOccurs="0" maxOccurs="unbounded">
</xsd:element>
<xsd:element name="tag"
type="j2ee:tagType"
minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="tag-file"
type="j2ee:tagFileType"
minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="function"
type="j2ee:functionType"
minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="taglib-extension"
type="j2ee:tld-extensionType"
minOccurs="0"
maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Taglib extensions are for tool use only and must not affect
the behavior of a container.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="version"
type="j2ee:dewey-versionType"
fixed="2.0"
use="required">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="description"
type="j2ee:descriptionType"
minOccurs="0"
maxOccurs="unbounded"/>
<xsd:element name="validator-class"
type="j2ee:fully-qualified-classType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="init-param"
type="j2ee:param-valueType"
minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:restriction base="j2ee:string">
<xsd:enumeration value="NESTED"/>
<xsd:enumeration value="AT_BEGIN"/>
<xsd:enumeration value="AT_END"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>
<xsd:annotation>
<xsd:documentation>
variable
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="description"
type="j2ee:descriptionType"
minOccurs="0" maxOccurs="unbounded"/>
<xsd:choice>
<xsd:element name="name-given"
type="j2ee:java-identifierType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="name-from-attribute"
type="j2ee:java-identifierType">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:choice>
<xsd:element name="variable-class"
type="j2ee:fully-qualified-classType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="declare"
type="j2ee:generic-booleanType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="scope"
type="j2ee:variable-scopeType"
minOccurs="0">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>
</xsd:schema>
The following is a DTD describing a Tag Library Descriptor file in JSP 1.2
format. This is the same DTD as "http://java.sun.com/dtd/web-
jsptaglibrary_1_2.dtd", except for some formatting changes to extract comments
and make them more readable:
<!--
This is the DTD defining the JavaServer Pages 1.2 Tag Library descriptor (.tld)
(XML) file format/syntax.
A Tag Library is a JAR file containing a valid instance of a Tag Library Descriptor
file, along with the appropriate implementation classes and other resources re-
quired to implement the actions defined therein. When deployed inside a JAR file,
the tag library descriptor files must be in the META-INF directory, or a subdirec-
tory of it. When deployed directly into a web application, the tag library descriptor
files must always be in the WEB-INF directory, or some subdirectory of it.
Packaged tag libraries must have at least one tag library descriptor file. The JSP
1.1 specification allowed for only a single TLD, in META-INF/taglib.tld, but in JSP
1.2 multiple tag libraries are allowed.
Use is subject to license terms.
-->
<!--
All JSP 1.2 tag library descriptors must include a DOCTYPE of the following form:
<!--
The taglib element is the document root, it defines:
<!ATTLIST taglib
id ID #IMPLIED
xmlns CDATA #FIXED “http://java.sun.com/JSP/TagLibraryDescriptor”>
<!--
The value of the tlib-version element describes this version (number) of the tagl-
ibrary. This element is mandatory.
<!--
The value of the jsp-version element describes the JSP version (number) this
taglibrary requires in order to function. This element is mandatory. The value that
should be used for JSP 1.2 is "1.2" (no quotes).
<!--
The value of the short-name element is a name that could be used by a JSP au-
thoring tool to create names with a mnemonic value; for example, it may be used
as the prefered prefix value in taglib directives.
Do not use white space, and do not start with digits or underscore.
<!--
The value of the uri element is a public URI that uniquely identifies the exact se-
mantics of this taglibrary.
-->
<!--
The value of the description element is an arbitrary text string describing the tag
library.
-->
<!--
The validator element provides information on an optional validator that can be
used to validate the conformance of a JSP page to using this tag library.
-->
<!--
The validator-class element defines the TagLibraryValidator class that can be
used to validate the conformance of a JSP page to using this tag library.
-->
<!--
The init-param element contains a name/value pair as an initialization param.
-->
<!--
The param-name element contains the name of a parameter.
-->
<!--
The param-value element contains the value of a parameter.
-->
<!--
The listener element defines an optional event listener object to be instantiated
and registered automatically.
-->
<!--
The listener-class element declares a class in the application that must be regis-
tered as a web application listener bean.
<!--
The tag element defines an action in this tag library. The tag element has one at-
tribute, id.
The tag element may have several subelements defining:
name The unique action name
tag-class The tag handler class implementing javax.servlet.jsp.tagext.Tag
tei-class An optional subclass of javax.servlet.jsp.tagext.TagExtraInfo
body-content The body content type
display-name A short name that is intended to be displayed by tools
small-icon Optional small-icon that can be used by tools
large-icon Optional large-icon that can be used by tools
description Optional tag-specific information
variable Optional scripting variable information
attribute All attributes of this action
example Optional informal description of an example of a use of this ac-
tion.
-->
<!--
The tag-class element indicates the subclass of javax.serlvet.jsp.tagext.Tag that
implements the request time semantics for this tag. This element is required.
<!--
The tei-class element indicates the subclass of javax.servlet.jsp.tagext.TagEx-
traInfo for this tag. The class is instantiated at translation time. This element is
optional.
<!--
The body-content element provides provides information on the content of the
body of this tag. This element is primarily intended for use by page composition
tools.
There are currently three values specified:
tagdependent The body of the tag is interpreted by the tag implementation it-
self, and is most likely in a different “langage”, e.g embedded SQL statements.
JSP The body of the tag contains nested JSP syntax
empty The body must be empty
This element is optional; the default value is JSP
<!--
The display-name element contains a short name that is intended to be displayed
by tools.
-->
<!--
The large-icon element contains the name of a file containing a large (32 x 32)
icon image. The icon can be used by tools. The file name is a relative path within
the tag library.
The image must be either in the JPEG or GIF format, and the file name must end
with the suffix “.jpg” or “.gif” respectively.
-->
<!--
The small-icon element contains the name of a file containing a small (16 x 16)
icon image. The icon can be used by tools. The file name is a relative path within
the tag library.
The image must be either in the JPEG or GIF format, and the file name must end
with the suffix “.jpg” or “.gif” respectively.
-->
<!--
The example element provides an informal description of an example of the use
of a tag.
-->
<!--
The variable element provides information on the scripting variables defined by
this tag.
It is a (translation time) error for an action that has one or more variable subele-
ments to have a TagExtraInfo class that returns a non-null object.
<!--
The name-given element provides the name for the scripting variable.
<!--
The value of the name-from-attribute element is the name of an attribute whose
(translation-time) value will give the name of the variable.
<!--
The variable-class element is the name of the class for the scripting variable.
<!--
The value of the declare element indicates whether the scripting variable is to be
defined or not. See TagExtraInfo for details.
<!--
The value of the scope element describes the scope of the scripting variable.
This element is optional and the default value is the string “NESTED”. The other
legal values are “AT_BEGIN” and “AT_END”.
-->
<!--
The attribute element defines an attribute for the nesting tag.
<!--
The name element defines the canonical name of a tag or attribute being defined
<!--
The value of the required element indicates if the nesting attribute is required or
optional. This attribute is optional and its default value is false.
<!--
The value of the rtexpvalue element indicates if the value of the attribute may be
dynamically calculated at request time, as opposed to a static value determined
at translation time. This attribute is optional and its default value is false
<!--
The value of the type element describes the Java type of the attributes value.
For static values (those determined at translation time) the type is always ja-
va.lang.String.
-->
The following is a DTD describing a Tag Library Descriptor file in JSP 1.1
format. This is the same DTD as http://java.sun.com/dtd/web-jsptaglibrary_1_1.dtd,
except for some formatting changes to extract comments and make them more
readable:
<!--
This is the DTD defining the JavaServer Pages 1.1 Tag Library descriptor (.tld)
(XML) file format/syntax.
A Tag Library is a JAR file containing a valid instance of a Tag Library Descriptor
(taglib.tld) file in the META-INF subdirectory, along with the appropriate imple-
menting classes, and other resources required toimplement the tags defined
therein.
<!--
The taglib tag is the document root, it defines:
tlibversion the version of the tag library implementation
jspversion the version of JSP the tag library depends upon
shortname a simple default short name that could be used by a JSP authoring
tool to create names with a mnemonic value; for example, the it may be used as
the prefered prefix value in taglib directives
uri a uri uniquely identifying this taglib
info a simple string describing the “use” of this taglib, should be user dis-
cernable
-->
<!--
Describes this version (number) of the taglibrary (dewey decimal)
<!--
Describes the JSP version (number) this taglibrary requires in order to function
(dewey decimal)
<!--
Defines a short (default) shortname to be used for tags and variable names used/
created by this tag library. Do not use white space, and do not start with digits or
underscore.
<!--
Defines a public URI that uniquely identifies this version of the taglibrary Leave it
empty if it does not apply.
-->
<!--
Defines an arbitrary text string descirbing the tag library
-->
<!--
The tag defines a unique tag in this tag library, defining:
- the unique tag/element name
- the subclass of javax.servlet.jsp.tagext.Tag implementation class
- an optional subclass of javax.servlet.jsp.tagext.TagExtraInfo
- the body content type (hint)
- optional tag-specific information
- any attributes
-->
<!--
Defines the subclass of javax.serlvet.jsp.tagext.Tag that implements the request
time semantics for this tag. (required)
<!--
Defines the subclass of javax.servlet.jsp.tagext.TagExtraInfo for this tag. (option-
al)
<!--
Provides a hint as to the content of the body of this tag. Primarily intended for use
by page composition tools.
<!--
The attribute tag defines an attribute for the nesting tag
<!--
Defines the canonical name of a tag or attribute being defined
<!--
Defines if the nesting attribute is required or optional.
If not present then the default is “false”, i.e the attribute is optional.
-->
<!--
Defines if the nesting attribute can have scriptlet expressions as a value, i.e the
value of the attribute may be dynamically calculated at request time, as opposed
to a static value determined at translation time.
If not present then the default is “false”, i.e the attribute has a static value
-->
This appendix details the algorithm containers are required to use in order to
determine the character encoding for a JSP file. See Chapter JSP.4, “International-
ization Issues” for details on where this algorithm is used. The algorithm is designed
to maximize convenience to the page author, while preserving backwards compati-
bility with previous versions of the JSP specification.
JSP.D.1Detection Algorithm
1. Decide whether the source file is a JSP page in standard syntax or a JSP
document in XML syntax.
a. If there is a <is-xml> element in a <jsp-property-group> that names this
file, then if it has the value "true", the file is a JSP document, and if it
has the value "false", the file is not a JSP document.
b. Otherwise, if the file name has the extension "jspx", the file is a JSP
document.
c. Otherwise, try to find a <jsp:root> element in the file.
i. Determine the initial encoding from the first four bytes of the file,
as described in appendix F.1 of the XML 1.0 specification. For the
byte sequence "3C 3F 78 6D", use ISO-8859-1; for the byte
sequence "4C 6F A7 94", use IBM037; for all other cases, use the
UTF-* or UCS-* encoding given in the appendix.
ii. Read the file using the initial encoding and search for a <jsp:root>
element. If the element is found and is the top element, the file is
a JSP document in XML syntax
d. Otherwise, the file is a JSP page in standard syntax.
2. Reset the file.
3. If the file is a JSP page in standard syntax, use these steps.
a. Check whether there is a JSP configuration element <page-encoding>
whose URL pattern matches this file.
b. Read the file using the initial encoding and search for a pageEncoding
attribute in a page declaration. The specification requires the attribute
to be found only if it is not preceded by non-ASCII characters, so
simplified implementations are allowed.
c. Report an error if there are a <page-encoding> configuration element
whose URL pattern matches this file and a pageEncoding attribute,
and the two name different encodings.
d. If there is a <page-encoding> configuration element whose URL
pattern matches this file, the page character encoding is the one named
in this element.
e. Otherwise, if there is a pageEncoding attribute, the page character
encoding is the one named in this attribute.
f. Otherwise, read the file using the initial encoding and search for a
charset value within a contentType attribute in a page declaration. If it
exists, the page character encoding is the one named in this charset
value. The specification requires the attribute to be found only if it is
not preceded by non-ASCII characters, so simplified implementations
are allowed.
g. Otherwise, the page character encoding is ISO-8859-1.
4. If the file is a JSP document in XML syntax, use these steps.
a. Determine the page character encoding as described in appendix F.1 of
the XML 1.0 specification. Note whether the encoding was named in
the encoding attribute of the XML prolog or just derived from the
initial bytes.
b. Check whether there is a JSP configuration element <page-encoding>
whose URL pattern matches this file.
c. Read the file using the detected encoding and search for a
pageEncoding attribute in a <jsp:directive.page> element.
This appendix lists the changes in the JavaServer Pages specification. This
appendix is non-normative.
• Requires that the JSP stratum is the default, for JSR-45 debugging.
• Added I18N detection algorithm appendix.
• Added element structure diagrams for TLD schema.
• Removed requirement on ordering of attribute setter calls, except for
<jsp:attribute>.
■
Character encoding is now determined for each file separately, even if one
file includes another using the include directive.
• Changed the semantics of <is-xml> so that a value of false simply indicates the
resource is not a JSP document, but rather a JSP page.
• Changed .jspx extension to only work with a Servlet 2.4 or greater web.xml.
• Synchronized behavior of error pages with the Servlet specification.
• Changed dynamic-attributes attribute of the tag directive to specify the name
of a Map to place the dynamic attributes into, instead of placing them directly
in the page scope. Dynamic attributes with a uri are ignored.
• Added alias attribute and name-from-attribute mechanism for tag files.
• Clarified behavior of Tag Library Validators when namespaces are redefined
in JSP documents.
• Added non-normative guidelines for JSR-45 line number mapping.
• Clarified that DTD validation of JSP Documents must be done by containers.
• Clarified that in JSP Documents the prefix "jsp" is not fixed for the namespace
http://java.sun.com/JSP/Page.
• Clarified that, if ’a’ is not a custom action, <a href="%= url %"> does not con-
tain a request-time attribute value whereas <a href="${url}"> does.
• Added glossary entries for tag file, JSP fragment, named attribute, JSP seg-
ment, classic tag handler, simple tag handler, dynamic attribute, and JSP con-
figuration.
• Added <jsp:element> standard action to standard syntax as well.
• Expression Language
■
Clarified behavior of EL functions whose implementations are declared to
return void.
■
Specified expected behavior when an EL function throws an exception.
■
Specified that the result of an EL expression in template text is quoted, to
help in preventing cross-site scripting attacks.
■
Made rules for coercing A to Number type N more specific.
■
Added special handling for all operators for BigInteger and BigDecimal types.
• Specified stricter rules for tag handler instance reuse to improve compatibility.
• Changed behavior of JspException being thrown from dynamic attributes to
be handled as though the exception came from another setter method, instead
of having come from doStartTag() or doEndTag().
• Clarified how dynamic attributes behave with respect to namespaces.
• Relaxed the need to call setParent( null ) on Simple Tag Handlers.
• Clarified that classic tag invocations with empty bodies will not cause body
methods to be invoked, even if the body content type for the tag is something
other than "empty".
• Some clarifications on how implicit taglib maps are constructed.
• EBNF Grammar Changes:
■
Fixed EBNF for Params, Fallback productions to allow for <jsp:body> to ap-
pear inside.
■
Clarified that <jsp:body> cannot be used to specify the body of <jsp:body> or
<jsp:attribute> and that <jsp:attribute> cannot be used to specify an attribute
of <jsp:attribute>.
■
Clarified that XML-style attributes, such as those used in directives, can be
separated from each other by whitespace.
■
Added <jsp:output> and <jsp:text> to grammar.
■
Corrected definition of <jsp:param>.
■
Fixed EBNF for <jsp:text>, <jsp:scriptlet>, <jsp:expression> and <jsp:decla-
• Split XML chapter into two chapters - one on JSP Documents and one on
XML Views of JSP Pages and JSP Documents. Rewrote large portions of JSP
Documents chapter.
• Changed semantics of SimpleTag so that if a body is not present, setJspBody()
is not called (instead of passing null).
• Added XML syntax for tag files (.tagx).
• Made preludes and codas illegal for JSP Documents (XML syntax).
and EVAL_PAGE constants (only for Simple Tag Handlers - Classic Tag Han-
dlers still use those constants).
• Clarified <jsp:attribute> can be used to specify only request-time expression
attributes, and can be used for standard actions, and custom actions imple-
mented using either Classic Tag Handlers or Simple Tag Handlers. Also clari-
fied the <jsp:body> value attribute can only be used for Simple Tag Handlers
and that <jsp:attribute> can be used to specify a fragment even for Classic Tag
Handlers.
• Modified the page scope handling for Jsp Fragments and Tag Files to be much
cleaner. Removed peekPageScope(), pushPageScope() and popPage-
Scope(). Instead, fragments are assumed to share the page scope with its con-
taining page, and tag files are required to create a Jsp Context Wrapper.
• Removed javax.servlet.jsp.tagext.AttributeNotSupportedException, and re-
placed it with a simple JspException which is just as effective.
• Added two constructors to JspTagException to allow specification of the root
cause.
• Made jspContext and jspBody fields protected in SimpleTagSupport.
• Updated I18N chapter to indicate Unicode 3.0 support and new details URL.
• Now requires JSR-45 strata name to be JSP.
• Clarified trim attribute of <jsp:attribute> is to be used at translation time.
• Fixed some minor typos (scattered).
• Renamed <el-evaluation> web.xml element to <el-enabled>
• Reorganized new features. Created a cohesive chapter about Tag Files. Simple
Tag Handler details were moved to Tag Extensions and to the API chapter.
Standard Action description was moved to Standard Action chapter.
• Added a root interface JspTag to cover Tag and SimpleTag.
• Moved all TLD DTDs to a single "Tag Library Descriptor Schemas" Appen-
dix and added the new JSP 2.0 XML Schema to that appendix.
• Added JSP 2.0 XML Schema, which is imported by the Servlet 2.4 Web Ap-
plication Deployment Descriptor.
• Updated page directive table and grammar to include isScriptingEnabled and
isELEnabled.
• Added language, import, isScriptingEnabled and isELEnabled attributes to
tag directive.
• Applied fixes to EBNF grammar based on JSP 2.0 Preview EA1 experience
• Clarified that jsp:id is now required and added TagExtraInfo.validate() and re-
quirement that container call it instead of TagExtraInfo.isValid().
• Reorganized slightly the EL chapter to emphasize the parts of the language
that do not depend on JSP details. Also removed the description of the API in
that chapter: the javadoc-generated chapter is more complete.
• Function names now need to be unique within a tag library; arity is not used to
disambiguate functions. This was done to simplify the EL language and the
decision can be revisited in later releases based on usage experience.
• Some refinements to the EL API: a new method was added that accepts a
VariableResolver instead of a JspContext, and the prefix/shortname map has
been split into two separate maps.
• Moved all the JSP configuration description into its own chapter.
• Reordered the EBNF description to be at the end of JSP 1.3.
• Restored some pieces in the Syntax chapter that were lost in an editing opera-
tion. The only substantive piece was the description of the <include-prelude>
and <include-coda> elements, which are now in the JSP configuration chapter.
• Added details on how to implement functions in EL.
• Upgraded major version from JSP 1.3 to JSP 2.0, added section to the Preface
explaining change.
• Added directive examples to JSP Fragments chapter.
• Moved section describing passing attribute values via <jsp:attribute> and
<jsp:body> to syntax chapter and moved definitions of these two standard ac-
tions to Standard Actions chapter, from JSP Fragments chapter.
• Added optional scope attribute to <jsp:invoke> and <jsp:doBody>.
• Improved and simplified the way tag files are packaged. One can now package
tag files in JARs or place them in a subdirectory of /WEB-INF/tags/ and ac-
cess them without specifying a uri.
• Changed SimpleTag to not extend Tag. Added TagAdapter to handle tag col-
laboration, and removed dependency on PageContext in SimpleTag. These
changes help make SimpleTag usable in environments other than Servlet re-
quest/response.
• Changed fragment invocation via <jsp:invoke> and <jsp:doBody> to be able
to expose their result as a java.io.Reader object instead of a String. This is ex-
pected to be more efficient.
• Added <include-prelude> and <include-coda> elements to <jsp-properties-
group>. Added a description in the Syntax Chapter.
• A new chapter on JSP fragments and supporting technologies such as the .tag
mechanism and simple tag handlers:
■
JSP fragments allow a portion of JSP code to be encapsulated into a Java ob-
ject which can be passed around and evaluated zero or more times.
■
The .tag mechanism allows page authors to use JSP syntax to write Custom
Actions.
■
Simple tag handlers integrates tightly with JSP fragments and allows for a
much easier and more natural invocation protocol for tag extensions.
JSP.E.10Changes Between JSP 1.2 Final Draft and JSP 2.0 ED1
This is the final version approved by JCP Executive Comittee; the document
was updated to reflect that status. All change bars were reset.
• Corrected a statement on the allowed return values for doStartTag() for Tag,
IterationTag and BodyTag.. PFD2 incorrectly indicated that "emtpy" tags
could only return SKIP_BODY; the correct statement is that tags whose body-
content is "empty" can only return SKIP_BODY.
• Reafirmed that, in a JSP page in XML syntax, the URI for jsp core actions is
important, not the prefix.
• Clarify that <?xml ... ?> is not required (as indicated by the XML spec).
• Clarified further the interpretation of whitespace on JSP documents.
for specialized implementations of well-known tag libraries like the JSP standard
tag library. This clarification affected the description of the tag element in
Section JSP.7.3 and the description of Tag.setParent() and TagSupport.findAnces-
torWithClass().
Removed the last paragraph on Section JSP.7.3.9; we don’t have any plans to
remove the well-know URI mechanism.
In general cleaned up the presentation of the computation of the taglib map
between a URI and a TLD resource path; the previous version was clunky.
Change bars are used in almost all chapters to indicate changes between PFD 1b
and PFD 2. The exception are Chapters 12 and 13 which are generated automati-
cally from the Java sources and have no change bars. Most changes are semantical,
but some of them are editorial.
• Add a comment to the DTD for the TLD indicating that a DOCTYPE is needed
and what its value is. No changes to the value.
• Removed the paragraph at the end of Section JSP.7.3.9 that used to contain
non-normative comments on the future of "well kwown URIs".
• Corrected the description of the valid values that can be passed to the flush at-
tribute of the include action in Section JSP.5.4.
• Clarified that <jsp:param> can only appear within <jsp:forward>, <jsp:in-
clude>, and <jsp:params>.
• Clarified that <jsp:params> and <jsp:fallback> can only appear within
<jsp:plugin>.
• Resolved a conflict in Section JSP.5.4 between the Servlet and the JSP specifi-
cation regarding how to treat modifications to headers in included actions.
• Section 10.1.1 in PFD1 incorrectly described the valid return values for
doStartTag() in tag handlers that implement the BodyTag interface. The cor-
rect valid values are SKIP_BODY, EVAL_BODY_INCLUDE and
EVAL_BODY_BUFFER. Section now indicates this.
PFD 1b is a draft that has mostly formating and a few editorial changes. This
draft is shown only to make it simpler to correlate changes between later drafts and
the previous drafts.
Change bars are used to indicate changes between PFD 1 and PFD 1b.
The following changes ocurred between the Public Draft 1 and the Proposed
Final Draft versions of the JSP 1.2 specification.
E.14.30 Deletions
E.14.31 Additions
E.14.32 Clarifications
• A tag handler object can be created with a simple “new()”; it needs not be a
fully fledged Beans, supporting the complete behavior of the ja-
va.beans.Beans.instantiate() method.
• Removed the “recommendation” that the <uri> element in a TLD be a URL to
anything.
• Clarified that extension dependency information in packaged tag libraries
should be honored.
• Clarified invocation and lifecycle of TagLibraryValidator.
• Clarified where TLDs may appear in a packaged JAR file.
• Clarified when are response.getWriter().
E.14.33 Changes
The following changes ocurred between the JSP 1.1 and JSP 1.2 Public Draft 1.
• Chapter 8 and 10 are now generated automatically from the javadoc sources.
• Created a new document to allow longer descriptions of uses of the technolo-
gy.
• Created a new I18N chapter to capture Servlet 2.3 implications and others
(mostly empty for PD1).
• Removed Implementation Notes and Future appendices, as they have not been
updated yet.
E.15.37 Clarifications
E.15.38 Changes
The JSP 1.1 specification builds on the JSP 1.0 specification. The following
changes ocurred between the JSP 1.0 final specification and the JSP 1.1 final specifi-
cation.
E.16.39 Additions
E.16.40 Changes
• Use Servlet 2.2 instead of Servlet 2.1 (as clarified in Appendix B), including
distributable JSP pages.
• jsp:plugin no longer can be implemented by just sending the contents of
jsp:fallback to the client.
• Reserved all request parameters starting with "jsp".
action An element in a JSP page that can act on implicit objects and other
server-side objects or can define new scripting variables. Actions follow the
XML syntax for elements with a start tag, a body and an end tag; if the body is
empty it can also use the empty tag syntax. The tag must use a prefix.
action, standard An action that is defined in the JSP specification and is always
available to a JSP file without being imported.
action, custom An action described in a portable manner by a tag library descrip-
tor and a collection of Java classes and imported into a JSP page by a taglib
directive.
Application Assembler A person that combines JSP pages, servlet classes,
HTML content, tag libraries, and other Web content into a deployable Web
application.
classic tag handler A tag handler that implements the javax.servlet.jsp.tagext.Tag
interface.
component contract The contract between a component and its container,
including life cycle management of the component and the APIs and proto-
cols that the container must support.
Component Provider A vendor that provides a component either as Java classes
or as JSP page source.
distributed container A JSP container that can run a Web application that is
tagged as distributable and is spread across multiple Java virtual machines
that might be running on different hosts.
declaration A scripting element that declares methods, variables, or both in a
JSP page. Syntactically it is delimited by the <%! and %> characters.
directive An element in a JSP page that gives an instruction to the JSP container
and is interpreted at translation time. Syntactically it is delimited by the <%@
and %> characters.
dynamic attribute An attribute, passed to a custom action, whose name is not
explicitly declared in the tag library descriptor.
element A portion of a JSP page that is recognized by the JSP translator. An ele-
ment can be a directive, an action, or a scripting element.
EL expression An element in a JSP page representing an expression to be parsed
and evaluated via the JSP Expression Language. Syntactically it is delimited
by the ${ and } characters.
expression Either a scripting expression or an EL expression.
fixed template data Any portions of a JSP file that are not described in the JSP
specification, such as HTML tags, XML tags, and text. The template data is
returned to the client in the response or is processed by a component.
implicit object A server-side object that is defined by the JSP container and is
always available in a JSP file without being declared. The implicit objects are
request, response, pageContext, session, application, out, config, page, and
exception for scriptlets and scripting expressions. The implicit objects are
pageContext, pageScope, requestScope, sessionScope, applicationScope,
param, paramValues, header, headerValues, cookie and initParam for EL
expressions.
JavaServer Pages technology An extensible Web technology that uses template
data, custom elements, scripting languages, and server-side Java objects to
return dynamic content to a client. Typically the template data is HTML or
XML elements, and in many cases the client is a Web browser.
JSP container A system-level entity that provides life cycle management and
runtime support for JSP and servlet components.
JSP configuration The deployment-time process by which the JSP container is
declaratively configured using a deployment descriptor.
JSP file A text file that contains JSP elements, forming a complete JSP page or
just a partial page that must be combined with other JSP files to form a com-
plete page. Most top-level JSP files have a .jsp extension, but other extensions
can be configured as well.
JSP fragment A portion of JSP code, translated into an implementation of the
javax.servlet.jsp.JspFragment abstract class.
JSP page One or more JSP files that form a syntactically complete description
for processing a request to create a response.
JSP page, frontA JSP page that receives an HTTP request directly from the cli-
ent. It creates, updates, and/or accesses some server-side data and then for-
wards the request to a presentation JSP page.
JSP page, presentation A JSP page that is intended for presentation purposes
only. It accesses and/or updates some server-side data and incorporates fixed
template data to create content that is sent to the client.
JSP page implementation class The Java programming language class, a servlet,
that is the runtime representation of a JSP page and which receives the request
object and updates the response object. The page implementation class can
use the services provided by the JSP container, including both the servlet and
the JSP APIs.
JSP page implementation object The instance of the JSP page implementation
class that receives the request object and updates the response object.
JSP segment A portion of JSP code defined in a separate file, and imported into
a page using the include directive.
named attribute A standard or custom action attribute whose value is defined
using the <jsp:attribute> standard action.
scripting element A declaration, scriptlet, or expression, whose tag syntax is
defined by the JSP specification, and whose content is written according to the
scripting language used in the JSP page. The JSP specification describes the
syntax and semantics for the case where the language page attribute is java.
is a valid scriptlet for the case where the language page attribute is java. Syn-
tactically a scriptlet is delimited by the <% and %> characters.
simple tag handler A tag handler that implements the javax.serv-
let.jsp.tagext.SimpleTag interface.
tag A piece of text between a left angle bracket and a right angle bracket that has
a name, can have attributes, and is part of an element in a JSP page. Tag
names are known to the JSP translator, either because the name is part of the
JSP specification (in the case of a standard action), or because it has been
introduced using a Tag Library (in the case of custom action).
tag file A text-based document that uses fixed template data and JSP elements to
define a custom action. The semantics of a tag file are realized at runtime by a
tag handler.
tag handler A Java class that implements the JspTag interface and is the run-
time representation of a custom action.
tag library A collection of custom actions described by a tag library descriptor
and Java classes.
tag library descriptor An XML document describing a tag library.
Tag Library Provider A vendor that provides a tag library. Typical examples
may be a JSP container vendor, a development group within a corporation, a
component vendor, or a service vendor that wants to provide easier use of
their services.
web application An application built for the Internet, an intranet, or an extranet.
web application, distributable A Web application that is written so that it can be
deployed in a Web container distributed across multiple Java virtual machines
running on the same host or different hosts. The deployment descriptor for
such an application uses the distributable element.
Web Application Deployer A person who deploys a Web application in a Web
container, specifying at least the root prefix for the Web application, and in a
J2EE environment, the security and resource mappings.
web component A servlet class or JSP page that runs in a JSP container and pro-
vides services in response to requests.
Web Container Provider A vendor that provides a servlet and JSP container that
support the corresponding component contracts.