<CFSERVLET 
    ...>
    <CFSERVLETPARAM 
    NAME="servlet parameter name" 
    VALUE="servlet parameter value"
    > 
    ...
    <CFSERVLETPARAM 
    NAME="servlet attribute name" 
    VARIABLE="ColdFusion variable name" 
    TYPE="INT" or "DOUBLE" or "BOOL" or "DATE" or "STRING"
    > 
    ...
</CFSERVLET>

The CFSERVLETPARAM is a child of CFSERVLET. It is used to pass data to the servlet. Each CFSERVLETPARAM tag within the CFSERVLET block passes a separate piece of data to the servlet.

See also CFSERVLET.

NAME

Required. If used with the VALUE attribute, it is the name of the servlet parameter. If used with the VARIABLE attribute, it is the name of the servlet attribute. See the Usage section for details on passing parameters. See the Usage section for details on passing parameters.

VALUE

Optional. The value of a name-value pair to be passed to the servlet as a parameter.

VARIABLE

Optional. The name of a ColdFusion variable. See the Usage section for details on passing parameters. The value of which will appear in the servlet as an attribute. See the TYPE attribute for a way to pass data type information to the Java servlet.

TYPE

Optional. The data type of the ColdFusion variable being passed. By default, ColdFusion usually passes variables as strings; however, to ensure that the data is correctly type on the Java side, you can specify any of the following types: INT, DOUBLE, BOOL, DATE, or STRING. See the Data Types table under Usage for information about how these types map to Java object types.

Usage

There are two different ways that CFSERVLETPARAM can be used to pass information to the servlet: by value or by reference. Depending on the method used, this information appears in the servlet either as a parameter (by value) or attribute (by reference).

The first passes name-value pairs by value. This method uses the attributes NAME and VALUE to pass a simple name-value string pair to the servlet. The NAME attribute represents the name of the servlet parameter from which the string specified in the VALUE attribute can be retrieved. Although the servlet can use these parameters as input, it cannot change their values in the ColdFusion template.

The second passes a ColdFusion variable to the servlet by reference. This method uses the attribute VARIABLE to pass the specified ColdFusion variable by reference to the servlet. Within the servlet, the variable data is made available as servlet attributes in the form of Java objects. On the Java side, the data can be manipulated, even changed, and those changes will, in turn, change the value of the associated ColdFusion variable.

When used in this mode, the NAME attribute represents the name of the servlet attribute that will be created to hold the value of the ColdFusion variable. The VARIABLE attribute represents the name, not the #value#, of a ColdFusion variable. This ability to directly share ColdFusion variables with a servlet is a powerful extension to the servlet API because it allows even complex ColdFusion objects such as structures and result sets to be directly accessed from Java. The following table shows the mapping between ColdFusion data types (specified with the TYPE attribute) and the corresponding Java objects.

Data Types: CF versus Java

CF Type Java Type
INT java.lang.Integer
DOUBLE java.lang.Double
BOOL java.lang.Bool
DATE java.util.Date
STRING java.lang.String
Array java.util.Vector
Structure java.util.Hashtable
CF query result set com.allaire.util.RecordSet (a WDDX-supplied utility class.)

Note: You need to have JRun 3.0 in order for the Name/Variable functionality to work. You can download the latest version of JRun at the following URL:

In addition, in order to return a modified attribute to ColdFusion, thereby changing the value of the ColdFusion variable, you need to call the servlet API setAttribute method from the servlet to reset the value of the attribute.