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.
This custom tag library requires no software other than a servlet container that supports the JavaServer Pages Specification, version 1.1 or higher.
Follow these steps to configure your web application with this tag library:
<taglib> <taglib-uri>http://jakarta.apache.org/taglibs/random-1.0</taglib-uri> <taglib-location>/WEB-INF/random.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/random-1.0" 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.
string | 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. |
number | 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 . |
string | Availability: 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 | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
id | Yes | No | 1.0 | ||
Script variable for use with the standard jsp:getProperty tag. |
|||||
length | No | No | 1.0 | ||
The length of the random string. Defaults to a length of 8. |
|||||
map | No | No | 1.0 | ||
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 | 1.0 | ||
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. |
|||||
algorithm | No | No | 1.0 | ||
The algorithm to be used if a SecureRandom object is going to be used to generate the random string. |
|||||
provider | No | No | 1.0 | ||
The package to search for the desired algorithm that is to be used for a SecureRandom object. |
|||||
Variables | Name | Scope | Availability | ||
id attribute value | End of tag to end of page | 1.0 | |||
Name used to retrieve the random string later in the page. |
|||||
Properties | Name | Get | Set | Availability | |
random | Yes | No | 1.0 | ||
The variable length randomly generated string from the named generator. |
|||||
Examples | Create a random string that is 8 characters long and that uses a charser of all characters. | ||||
|
number | Availability: 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 | Empty | ||||
Restrictions |
None |
||||
Attributes | Name | Required | Runtime Expression Evaluation | Availability | |
id | Yes | No | 1.0 | ||
Script variable for use with the standard jsp:getProperty tag. |
|||||
range | No | No | 1.0 | ||
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. |
|||||
algorithm | No | No | 1.0 | ||
The algorithm to be used if a SecureRandom object is going to be used to generate the random string. |
|||||
provider | No | No | 1.0 | ||
The package to search for the desired algorithm that is to be used for a SecureRandom object. |
|||||
Variables | Name | Scope | Availability | ||
id attribute value | End of tag to end of page | 1.0 | |||
Name used to retrieve the random number later in the page. |
|||||
Properties | Name | Get | Set | Availability | |
random | Yes | No | 1.0 | ||
The variable length randomly generated number as a Java Number object. In a JSP page the number is printed out as a string. |
|||||
Examples | Create a default random number in the range 10000000-99999999. | ||||
|
See the example application random-examples.war for examples of the usage of the tags from this custom tag library.
Java programmers can view the java class documentation for this tag library as javadocs.
Review the complete revision history of this tag library.