cfservletparam

Description

A child of cfservlet. It passes data to the servlet. Each cfservletparam tag within the cfservlet block passes a separate piece of data to the servlet.

Category

Java servlet and Java object tags

Syntax


<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> 

See also

cfobject, cfservlet

Attributes

Attribute
Description
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.
value
Optional. Value of a name-value pair 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 appears 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 the correct 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

The cfservletparam tag can be used in two ways to pass information to a 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 method 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 method 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, or changed, changing the value of the associated ColdFusion variable.

When used in this mode, the name attribute represents the name of the servlet attribute that is 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.
Type
In Java
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
ColdFusion query result
com.allaire.util.RecordSet (a WDDX-supplied utility class)


Note

In order for the Name/Variable functionality to work, you must have JRun 3.0 or later. Download the latest version of JRun at the following URL:
http://www.allaire.com/products/Jrun/


To return a modified attribute to ColdFusion, thereby changing the value of the ColdFusion variable, you must call the servlet API setAttribute method from the servlet to reset the value of the attribute.

Example

<cfservlet 

  code = "MyServletName" 

  JRunProxy = "236.3.3.4:8083" 

  timeout = "300"

  writeOutput = "Yes"

  debug = "Yes">

  <cfservletparam name = "Param1" value = "Value1"> 

  <cfservletparam name = "Param2" value = "Value2">

  <cfservletparam name = "Attribute1" variable = "CFVar1" 

    type = "BOOL">

  <cfservletparam name = "Attribute2" variable = "CFVar2">

</cfservlet>



Banner.Novgorod.Ru