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

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.