User Guide

Table Of Contents
932 Chapter 37: Integrating J2EE and Java Elements in CFML Applications
}
else if (Grade.equals("DEVELOPER")) {
JobGrade = 1;
}
}
public int GetJobGrade() {
return JobGrade;
}
}
A CFML page that uses the Employee class
Save the following text as JEmployee.cfm:
<html>
<body>
<cfobject action="create" type="java" class="Employee" name="emp">
<!--- <cfset emp.init()> --->
<cfset emp.firstname="john">
<cfset emp.lastname="doe">
<cfset firstname=emp.firstname>
<cfset lastname=emp.lastname>
</body>
<cfoutput>
Employee name is #firstname# #lastname#
</cfoutput>
</html>
When you view the page in your browser, you get the following output:
Employee name is john doe
Reviewing the code
The following table describes the CFML code and its function:
Code Description
<cfobject action=create
type=java class=Employee
name=emp>
Loads the Employee Java class and gives it an object name of
emp.
<!--- <cfset emp.init()> --->
Does not call a constructor. ColdFusion invokes the default
constructor when it first uses the class; in this case, when it
processes the next line.
<cfset emp.firstname="john">
<cfset emp.lastname="doe">
Sets the public fields in the emp object to your values.
<cfset firstname=emp.firstname>
<cfset lastname=emp.lastname>
Gets the field values back from emp object.
<cfoutput>
Employee name is #firstname#
#lastname#
</cfoutput>
Displays the retrieved values.