A JavaServer Page (JSP) tag is a Java class that encapsulates functionality,
like conditional logic, or database access, that can be used from a JSP. The
use of tags makes it easy to interface with business logic in a transparent
way. It also keeps the JSPs manageable and easy to read. Instead of writing
a lot of inline Java code, a simple call to a tag can be made. Only when the
.jsp
is run does the tag get substituted with the corresponding
code, completely transparent to both the JSP developer and the users.
JSP 1.1 supports custom tag libraries.This means that you can write your own
sets of tags and call them in your JSPs. To use these custom tag libraries,
the corresponding Java classes need to be placed in a location where the JSP
container can execute them and the Tag Library Descriptor (or .tld
)
file needs to be edited. The .tld
file defines tag names, tag attributes
and class file locations. Furthermore, a taglib
directive needs
to be issued in the JSP before calls to the custom tags are made.
Here is an example of the use of a custom JSP tag:
<%@ taglib uri="/WEB-INF/lib/reports_tld.jar" prefix="test" %>
<HTML>
<BODY>
<P>Hello The time is
<test:curTime/>
</P>
</BODY>
</HTML>
In the preceding example, the first line of the JSP specifies the custom tag library
definition file and defines a prefix that is to be used for the custom tags.
This is also refered to as the taglib
directive. In this case the
prefix is test
. Inside the HTML body, the custom tag test:curTime
is then called. When the JSP is requested from the server, the JSP container
will see that tags with prefix test
are to be handled according
to the specified .tld
file. The Java class that corresponds with
the function that is being called for will in this case generate the current
time as output, which will in turn be added to the existing HTML and the combined
result will be seen by the end user.
What is important is that the internal workings of the Java class that contains the custom tag's functionality is not all coded inside the JSP. Instead, they are simple tags that any Web developer can easily use.
By default, the custom JSP tags defined by Oracle Reports use the rw
prefix. You may, however, choose any prefix.
The <rw:report>
and <rw:objects>
tags, respectively, delimit and define the report block. Inside these tags,
other custom tags define the content and the look and feel of the report data.
A comprehensive example of the use of most of the Oracle Reports custom JSP
tags is shown in the <rw:report>
tag description.
By default, a new JSP created in Reports Builder contains the following:
<%@ page contentType="text/html;charset=ISO-8859-1" %>
If you are creating your JSP outside Reports Builder, you should ensure
that it contains similar encoding information.
About JavaServer Pages and servlets
Copyright © 1984, 2005, Oracle. All rights reserved.