ColdFusion MX Professional Projects

ColdFusion MX implements code reusability by incorporating functionality from other technologies, such as Java or COM, into a ColdFusion application. For example, consider a Java class that connects with an Oracle database and performs a certain task on the data stored in the database. ColdFusion lets you call and use the Java class directly in your page to incorporate its functionality in a ColdFusion page.

Creating an Instance of a Java Object

To create an instance of a Java object in your ColdFusion page, you need to use the <cfobject> tag. You can use the instance of the Java object to retrieve and modify attribute values and call methods and functions defined in the Java class.

Accessing Java Classes Using ColdFusion MX Server

You can use the <cfobject> tag to create an object instance of the Java class. To use the instance in a ColdFusion page, place the Java classes in any one of these locations:

Note

ColdFusion Server comes with a JVM that calls or runs a Java object to be used by ColdFusion tags, such as <cfset>, in a ColdFusion page.

To use ColdFusion Administrator to specify the JVM class path where you can store the class files that you want to use in your ColdFusion page, perform the following steps:

  1. Launch ColdFusion Administrator from the Windows Start menu by choosing Start, Programs, Macromedia ColdFusion MX, Administrator. This opens the ColdFusion Administrator window, divided into two frames, in your Web browser.

  2. Click the Java and JVM link under the SERVER SETTINGS heading in the left frame of the ColdFusion Administrator window. The Java and JVM Settings page appears in the right frame of the ColdFusion Administrator window, as shown in Figure C.1.

    Figure C.1: The Java and JVM Settings page.

  3. In the Class Path box, type the path of the directory where you'll store your Java classes, such as d:\myclasses. Figure C.2 shows how to specify the JVM class path in ColdFusion Administrator.

    Figure C.2: Setting the JVM class path.

  4. Click Submit Changes. You need to stop and restart ColdFusion MX Server for the new settings to take effect.

STOPPING AND RESTARTING COLDFUSION MX SERVER IN WINDOWS 2000

To stop and restart ColdFusion MX Server in Windows 2000:

  1. From the Windows Start menu, select Start, Settings, Control Panel to open the Windows Control Panel.

  2. Double-click the Administrative Tools icon.

  3. Double-click the Services icon in the Administrative Tools window to view all the services running in the computer.

  4. Select ColdFusion MX Application Server in the right pane of the Services window.

  5. Right-click and choose Stop from the pop-up menu to stop the ColdFusion MX Application Server.

  6. Finally, right-click again and choose Start from the pop-up menu to restart the ColdFusion MX Application Server.

Using the <cfobject> Tag

The <cfobject> tag creates an object instance in a ColdFusion page. This tag can be used to create the types of objects listed in Table C.1.

Table C.1: Objects That Can Be Created Using the <cfobject> Tag

Object Type

Description

Component Object Model (COM) object

Creates an instance of a Microsoft COM object that can be an ActiveX Dynamic Link Library (DLL)

cfcomponent object

Creates a ColdFusion component object in a ColdFusion page

Java object

Creates an object instance of a Java class in a ColdFusion page

The <cfobject> tag uses the type attribute to determine the type of object, COM or Java, within a ColdFusion page. You can use this tag to create a Java object by specifying the value of the type attribute as Java. Here's the syntax of the <cfobject> tag:

<cfobject type="Java" action="Create" class= "Java_class_name" name="object_name">

The preceding syntax contains these attributes:

This code uses the <cfobject> tag to create an object instance of a Java class in a ColdFusion page:

<cfobject type="Java" action="Create" name="myobj">

Категории