280
Developing Web Applications with ColdFusion
To create a Java CFX:
1.
Create a new source file in your editor.
2.
Enter the code, for example, the code below illustrates the creation of a very
simple Java CFX named
SimpleJavaCFX
that writes a text string back to the calling
page:
import com.allaire.cfx.* ;
public class HelloColdFusion implements CustomTag
{
public void processRequest( Request request, Response response )
throws Exception
{
String strName = request.getAttribute( "NAME" ) ;
response.write( "Hello, " + strName ) ;
}
}
3.
Save the file as
HelloColdFusion.java
in the
classes
subdirectory
4.
Compile the java source file into a class file using the java compiler. If you are
using the command line tools bundled with the JDK, you do this using the
following command line, which you execute from within the
classes
directory:
javac -classpath cfx.jar HelloColdFusion.java
Note
The above command will only work if the java compiler (
javac.exe
)
is in your path. If it is not in your path, specify the fully qualified
path, for example:
c:\jdk12\bin\javac
on Windows NT, or
/usr/java/bin/java
c on Solaris
If you receive errors during compilation, check the source code to make sure you have
entered it correctly. If no errors occur, you have just successfully written your first Java
CFX!
As you can see, implementing the basic
CustomTag
interface is very straightforward.
This is all a Java class has to do to be callable from a CFML page.
Processing Requests
Implementing a Java CFX requires interaction with the
Request
and
Response
objects
passed to the
processRequest
method. In addition, CFXs that need to work with
ColdFusion queries will also interface with the
Query
object. The
com.allaire.cfx
package, located in the
classes/cfx.jar
archive contains the
Request
,
Response
, and
Query
objects.
A basic overview of each of these object types is provided below. To see a complete
example Java CFX that uses
Request
,
Response
, and
Query
objects, see the
“ZipBrowser
Example” on page 284
.
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...