O'Reilly logo

Programming ColdFusion by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Invoking Java Servlets

The CFSERVLET tag can invoke a Java servlet from within a ColdFusion template. The CFSERVLET tag requires Allaire’s JRun software be installed in order to work. For more information on JRun, see Allaire’s web site at http://www.allaire.com.

Assuming you already have JRun installed, invoking a servlet is a matter of calling the CFSERVLET tag in your template. Attributes and parameters can be passed to the Java servlet by nesting CFSERVLETPARAM tags within the CFSERVLET tag. Example 23-7 shows the syntax for calling a servlet and passing it parameters.

Example 23-7. Invoking a Java Servlet with CFSERVLET

<CFSERVLET JRUNPROXY="127.0.0.1:51000" CODE="MyServlet" TIMEOUT="90" DEBUG="Yes" WRITEOUTPUT="No"> <!--- pass attributes. Each VARIABLE represents a variable created in ColdFusion ---> <CFSERVLETPARAM NAME="parString" VARIABLE="MyString" TYPE="STRING"> <CFSERVLETPARAM NAME="parDouble" VARIABLE="MyReal" TYPE="REAL"> <CFSERVLETPARAM NAME="parDate" VARIABLE="MyDate" TYPE="DATE"> <CFSERVLETPARAM NAME="parInt" VARIABLE="MyInt" TYPE="INT"> <CFSERVLETPARAM NAME="parBool" VARIABLE="MyBool" TYPE="BOOL"> <CFSERVLETPARAM NAME="parQuery" VARIABLE="MyQuery"> <CFSERVLETPARAM NAME="parStruct" VARIABLE="MyStruct"> <CFSERVLETPARAM NAME="parArray" VARIABLE="MyArray"> <!--- pass parameter ---> <CFSERVLETPARAM NAME="attString" VALUE="Hello World"> </CFSERVLET> <!--- output the text returned from the servlet to the browser ---> <CFOUTPUT> #CFServlet.Output# </CFOUTPUT> <HR> <!--- ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required