The utility
custom tag library contains examples of some
basic tags. It illustrates several custom tag library code techniques.
This custom tag library requires no software other than a servlet container that supports the JavaServer Pages Specification, version 1.1.
Follow these steps to configure your web application with this tag library:
utility/utility.tld
)
to the /WEB-INF
subdirectory of your web application.
utility/utility.jar
) to the
/WEB-INF/lib
subdirectory of your web application.
<taglib>
element to your web application
deployment descriptor in /WEB-INF/web.xml
like this:
<taglib> <taglib-uri>http://jakarta.apache.org/taglibs/utility</taglib-uri> <taglib-location>/WEB-INF/utility.tld</taglib-location> </taglib>
To use the tags from this library in your JSP pages, add the following directive at the top of each page:
<%@ taglib uri="http://jakarta.apache.org/taglibs/utility" prefix="x" %>where "x" is the tag name prefix you wish to use for tags from this library. You can change this value to any prefix you like.
The utility
Tag Library contains the following tags:
The Hello
tag prints out the text "Hello World". It does not
have any attributes.
Attribute
|
Description
|
Required
|
---|---|---|
-
|
-
|
-
|
The MacroCopy
tag copies the attribute text to a Writer.
Attribute
|
Description
|
Required
|
---|---|---|
name
|
Name associated with the text to be copied. Any
string value.
|
yes
|
The MacroPaste
tag pastes the text specified by a Writer.
Attribute
|
Description
|
Required
|
---|---|---|
name
|
Name associated with the text to be pasted. Any
string value.
|
yes
|
The ShowSource
tag takes a jspFile and copies the contents
to a Writer.
Attribute
|
Description
|
Required
|
---|---|---|
jspFile
|
The filename and relative path of the jsp file.
Any string value.
|
yes
|
The Include
tag includes in-line the output of the specified
url.
Attribute
|
Description
|
Required
|
---|---|---|
url
|
Any valid url.
|
yes
|
The If
tag is a basic conditional tag.
Attribute
|
Description
|
Required
|
---|---|---|
predicate
|
Any string value.
|
yes
|
The For
tag is a basic looping tag.
Attribute
|
Description
|
Required
|
---|---|---|
iterations
|
Number of loop iterations to be completed. Any string
integer value.
|
yes
|
varName
|
Variable name associated with the For loop. Any
string value.
|
no
|
begin
|
Loop starting value. Any string integer value.
|
no
|
The useBean
tag associates an instance of a Java object with the given id.
Either the classname or type must be specified.
The beanName and classname attributes are mutually exclusive, you can't specify both.
Attribute
|
Description
|
Required
|
---|---|---|
id
|
Uniquely identifies the bean to the JSP container and page. Any string value.
|
yes
|
scope
|
page|request|session|application
|
no
|
classname
|
name of class that defines the implementation of the object.
|
no
|
type
|
type of the scripting variable defined
|
no
|
beanName
|
The name of the bean as expected by the instantiate() method of the java.beans.Beans class
|
no
|
processRequest
|
true|false. JSP 0.92 compatibility.
|
no
|
The Validate
tag generates Javascript to validate the HTML
form.
Attribute
|
Description
|
Required
|
---|---|---|
name
|
Name of the form. Any string value.
|
yes
|
method
|
Name of the Javascript function to be generated. Any string value.
|
yes
|
reqdFields
|
Comma separated mandatory field list. Any string value.
|
yes
|