2010-04-14 - Jakarta Taglibs has been retired.

For more information, please explore the Attic.

Tag reference sheet

Tag library reference for the following tag libraries:

Random Tag library

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. Both the RandomStrgTag and the RandomNum tag support the use of a SecureRandom object in the generation of their random objects. To make use of this option there are two attributes that can be used: algorithm and provider. The algorithm attribute is required, and it is the name of the algorithm that the SecureRandom object will use. The provider attribute is optional, if there are multiples of the same algorithm available, and the desired algorithm exists within a specific package, then that package can be specified here.

This is version 1.0.2.

  • number Set the properties of a random number generator
  • string Set the properties of a variable length random string generator

Required attributes are marked with a *

<random:number>

Set the properties of a random number generator. A new random number will be generated each time the null tag is used to access the generator.

Can contain: Empty

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 null 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 null tag.
      
<jsp:getProperty name="random2" property="random"/> 
               
Use the algorithm and provider attributes to use a SecureRandom object instead 
of just a Random object when creating the random string.  Use the default settings 
for range of the number.  The algorithm is SHA1PRNG and the provider is SUN.
 
<rand:number id="random3" algorithm="SHA1PRNG" provider="SUN"/>
       
Get the random number that was set up above, using the null tag.
 
<jsp:getProperty name="random3" property="random"/> 
       
      

Attributes

Name Description Type
algorithm The algorithm to be used if a SecureRandom object is going to be used to generate the random string. String
id Script variable for use with the standard null tag. String
provider The package to search for the desired algorithm that is to be used for a SecureRandom object. String
range 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. String

Variables

Name Type Scope Description
specified via id org.apache.taglibs.random.RandomNum AT_END Name used to retrieve the random number later in the page.

<random:string>

Set the properties of a variable length random string generator. A new random string will be created every time the null tag is used to access the generator.

Can contain: Empty

Example

Create a random string that is 8 characters long and that uses a charser of all characters.
 
<rand:string id="random1" charset="all"/>
       
Get the random string that was set up above, with a null 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 null tag.
 
<jsp:getProperty name="random2" property="random"/>
       
Create the same random string as above only make it 15 characters long.
 
<rand:string id="random3" charset="A-Z" length="15"/>
       
Get the random string that was set up above, with a null 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 ! @ # \\ \- + ? &amp; $"/>
       
Get the random string that was set up above, with a null 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 null tag.
 
<jsp:getProperty name="random5" property="random"/> 
       
Use the algorithm and provider attributes to use a SecureRandom object instead 
of just a Random object when creating the random string.  Use the default 
settings for range and length of the string.  The algorithm is SHA1PRNG and the 
provider is SUN.
 
<rand:string id="random6" algorithm="SHA1PRNG" provider="SUN"/>
       
Get the random string that was set up above, with a null tag.
 
<jsp:getProperty name="random6" property="random"/> 
       
      

Attributes

Name Description Type
algorithm The algorithm to be used if a SecureRandom object is going to be used to generate the random string. String
charset 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. String
id Script variable for use with the standard null tag. String
length The length of the random string. Defaults to a length of 8. String
map 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. String
provider The package to search for the desired algorithm that is to be used for a SecureRandom object. String

Variables

Name Type Scope Description
specified via id org.apache.taglibs.random.RandomStrg AT_END Name used to retrieve the random string later in the page.