Jakarta Project: RANDOM JSP Tag Library
Version 1.0
Table of Contents
Overview
Requirements
Configuration
Tag Summary
Tag Reference
Examples
Javadocs
Revision History
Overview
The Random tag library creates random strings and random numbers. You may
specify a set of allowable characters as well as the length for randomly
generated strings. You may specify a range of allowable integers or a
random floating point number between zero and one for randomly generated
numbers.
Requirements
This custom tag library requires no software other than a servlet container
that supports the JavaServer Pages Specification, version 1.1.
Configuration
Follow these steps to configure your web application with this tag library:
To use the tags from this library in your JSP pages, add the following
directive at the top of each page:
<%@ taglib uri="random.jar" prefix="rand" %>
where "rand" 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 prefix rand is used in the examples below.
Tag Summary
Tag Reference
string |
Availability: version 1.0 |
|
Set the properties of a variable length random string generator.
A new random string will be created every time the
jsp:getProperty tag is used to access the generator.
|
|
Tag Body |
empty |
Script Variable |
Yes |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
id |
Yes |
No |
Script variable for use with the standard
jsp:getProperty tag.
|
length |
No |
No |
The length of the random string. Defaults to a length of 8.
|
map |
No |
No |
Attribute name of a Bean or Script variable which is a Java
HashMap object. The random string generated will be a new
unique key for use as a key for the HashMap.
|
charset |
No |
No |
The set of characters to use when creating the random
string. The following characters can be used as a charset
a-zA-Z0-9 ! @ # $ % ^ & * ( ) _ \- + = { } [ ] \\
| : ; \" ' < > , . ? /
The backslash, hyphen, and double quotes
characters must be escaped with a \: like this
\\, \-, and \".
Lowercase alpha characters can be specified using
a range like "a-z" or "f-r", the same can be done with
uppercase letters A-Z and digits 0-9. To use the entire
character set, set charset="all".
Single characters must be separated by a space.
Charset defaults to a value of a-zA-Z0-9.
|
|
Properties |
|
Name |
Get |
Set |
random |
Yes |
No |
Returns the variable length randomly generated string from
the named generator. |
|
Example |
<!-- Create a random string that is 8 characters long and that -->
<!-- uses a charset of all characters -->
<rand:string id="random1" charset="all"/>
<!-- Get the random string that was set up above, with a -->
<!--jsp:getProperty tag -->
<jsp:getProperty name="random1" property="random"/>
<!-- Create a random string that only uses uppercase letters -->
<rand:string id="random2" charset="A-Z"/>
<!-- Get the random string that was set up above, with a -->
<!--jsp:getProperty tag -->
<jsp:getProperty name="random2" property="random"/>
<!-- Create the same random string as above only make it -->
<!-- 15 character long -->
<rand:string id="random3" charset="A-Z" length="15"/>
<!-- Get the random string that was set up above, with a -->
<!--jsp:getProperty tag -->
<jsp:getProperty name="random3" property="random"/>
<!-- Create a random string that uses the following charset -->
<!-- A-Z ! @ # \\ \- + ? & $
<rand:string id="random4" charset="A-Z ! @ # \\ \- + ? & $"/>
<!-- Get the random string that was set up above, with a -->
<!--jsp:getProperty tag -->
<jsp:getProperty name="random4" property="random"/>
<!-- Create the default random string that uses a hashmap named -->
<!-- passkeys to make sure each randomly created string is unique. -->
<!-- This string defaults to a charset of a-zA-Z0-9. -->
<rand:string id="random5" map="passkeys"/>
<!-- Get the random string that was set up above, with a -->
<!--jsp:getProperty tag -->
<jsp:getProperty name="random5" property="random"/>
|
|
number |
Availability: version 1.0 |
|
Set the properties of a random number generator. A new random
number will be generated each time the jsp:getProperty tag
is used to access the generator .
|
|
Tag Body |
JSP |
Script Variable |
Yes |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
id |
Yes |
No |
Script variable for use with the standard
jsp:getProperty tag.
|
range |
No |
No |
This parameter determines the lower and upper bound from
which to select the random number. If a range of 0-1 is
selected, the tag will automatically create a float value
between 0 and 1. The default range is the digits 0 to 100.
Max size of the random number is limited by the size of the
primitive data type of long.
|
|
Properties |
|
Name |
Get |
Set |
random |
Yes |
No |
Returns the randomly generated number as a Java Number object.
In a JSP page the number is printed out as a string. |
|
Example |
<!-- Create a default random number in the range 10000000-99999999. -->
<rand:number id="random1" range="10000000-99999999"/>
<!-- Get the random number, that was set up above, using the -->
<!-- jsp:getProperty tag. -->
<jsp:getProperty name="random1" property="random"/>
<!-- Create a random number that is a float value by setting the -->
<!-- range to 0-1 -->
<rand:number id="random2" range="0-1"/>
<!-- Get the random number, that was set up above, using the -->
<!-- jsp:getProperty tag. -->
<jsp:getProperty name="random2" property="random"/>
|
|
Examples
See random-examples.war for examples that use tags from this custom tag library.
Javadocs
Java programmers can view the java class documentation for this tag library
as javadocs.
Revision History
Review the complete revision history of this tag
library.