|
Comments
|
Today's Top SOA Links
BF on CF Java For CFers - Part 3
Java For CFers - Part 3
By: Ben Forta
Dec. 26, 2000 12:00 AM
In my last two columns we looked at JavaServer Pages (JSP) and compared ColdFusion development to JSP development. As explained, JSP is designed to dramatically lower the cost of entry into the Java development world, and JRun, in particular (with its tag libraries), does even more to deliver on this promise. We ColdFusion developers know that a CF-Java convergence is on the way. We also know that when this happens, knowledge of Java won't be required and we'll be able to develop CF code as we do now. However, as explained earlier in this series, there are compelling reasons to consider Java-based development and the Java platform - even for ColdFusion developers and even right now.
Why Leverage Java? In addition and as I've written in previous columns, ColdFusion developers need to think about code reuse, abstraction, encapsulation, and componentization. As the next generation of ColdFusion will be built upon a Java platform, using Java components within your code ensures that you're walking the same path Allaire is. All said and done, ColdFusion developers need to take a good look at Java - right away.
Integrating ColdFusion and Java
Of these three options <CF-SERVLET> is, for all intents and purposes, the least useful. You'll seldom want to display servlet results as is (if you did, you'd probably have used the servlet directly); if you need to manipulate the output, you can use <CFHTTP> to call the page. For leveraging Java within your ColdFusion code <CFOBJECT> is probably the most useful in that it allows you to interact with generic Java (unlike the CFX interface that requires CF-specific Java coding). However, the CFX interface does have an advantage - it's far more CF aware (for example, it can read and write queries).
Java via <CFOBJECT> The following code snippet (based on example code that's included with ColdFusion) invokes Java code (see Listing 1) that creates a JPEG image containing user-supplied text: <CFOBJECT TYPE="JAVA" ACTION="Create" NAME="image" CLASS="HelloWorldGraphic"> <CFOBJECT> requires that the Java class is specified along with a name to refer to the instance. That name is then used to pass attributes and invoke specific methods. <CFSCRIPT> can also be used to invoke Java code, and the syntax this way is even cleaner: <CFSCRIPT> As you can see, calling Java code isn't difficult at all. As long as you know the names of the required methods and attributes it's just a matter of calling <CFOBJECT> and <CFSET> (or their <CFSCRIPT> counterparts) as needed.
Custom Tag Wrappers <CFPARAM NAME="ATTRIBUTES.message" DEFAULT="">Now invoking Java code is as complex as this: <CF_HelloWorldGraphic MESSAGE="Hello Ben">
Summary Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||