Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 1148

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
<cfscript>
function GetHostAddress(host) {
// Define the function local variables.
var iaddrClass="";
var address="";
// Initialize the Java class.
iaddrClass=CreateObject("java", "java.net.InetAddress");
// Get the address object.
address=iaddrClass.getByName(host);
// Return the address
return address.getHostAddress();
}
</cfscript>
<cfoutput>#gethostaddress("adobe.com")#</cfoutput>
Using an EJB
ColdFusion can use EJBs that JRun 4.0 servers provide. The JRun server jrun.jar file must have the same version as the
jrun.jar file in ColdFusion.
To call an EJB, you use
cfobject
Have a properly deployed EJB running on a J2EE server. The bean must be registered with the JNDI server.
1
Have the following information:
2
• Name of the EJB server
• Port number of the JNDI naming service on the EJB server
• Name of the EJB, as registered with the naming service
3
Install the EJB home and component interface compiled classes on your ColdFusion web server, either as class files
in the web_root/WEB-INF/classes directory or packaged in a JAR file the web_root/WEB-INF/lib directory.
Note: To use an EJB served by a JRUN server, your ColdFusion installation and the JRun server that hosts the EJB must
have the same version of the jrun.jar file (located in cf_root\runtime\lib directory in ColdFusion).
Although the specific steps for using an EJB depend on the EJB server and on the EJB itself, they generally correspond
to the following order.
Use the
tag to create an object of the JNDI naming context class (javax.naming.Context). You use fields
1
cfobject
from this class to define the information that you use to locate the EJB. Because you only use fields, you do not
initialize the object.
Use the
tag to create a java.util.Properties class object to contain the context object properties.
2
cfobject
3
Call the
method to initialize the Properties object.
init
Set the Properties object to contain the properties that are required to create an initial JNDI naming context. These
4
properties include the INITIAL_CONTEXT_FACTORY and PROVIDER_URL properties. You could also need to
provide SECURITY_PRINCIPAL and SECURITY_CREDENTIALS values required for secure access to the
naming context. For more information on these properties, see the JNDI documentation.
Use the
tag to create the JNDI InitialContext (javax.naming. InitialContext) object.
5
cfobject
Call the
method for the InitialContext object with the Properties object values to initialize the object.
6
init
7
Call the
method of the InitialContextext object to get a reference to the home interface for the bean that
lookup
you want. Specify the JNDI name of the bean as the
8
Call the
method of the bean home object to create an instance of the bean. If you are using Entity beans,
create
you typically use a finder method instead. A finder method locates one or more existing entity beans.
to create and call the appropriate objects. Before you use an EJB, do the following:
lookup
Last updated 1/20/2012
argument.
1143

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents