by Christian Cantrell

 Comments (13)

Created

September 8, 2003

There are four basic ways to use Java with ColdFusion:

  1. CFX tags
  2. JSP tags
  3. Using CFOBJECT or createObject() to accesses custom classes in your classpath
  4. Direct embedding (usually using CFScript)

CFX tags have a very straightforward interface. You simply implement a function called processRequest contained in the interface com.allaire.cfx.CustomTag, and work with the Request and Response objects that get passed in. CFX tags are the easiest way to implement ColdFusion tags in Java. The JSP custom tag interface is much more complex and flexible, allowing you to respond to very specific tag parsing events, nest tags, and work with body content. Using the CFOBJECT tag or createObject function is as easy or difficult or as the APIs you are accessing, while the simplest way to work with Java in ColdFusion is probably to embed it directly, typically using CFScript.

How often do you find yourself using Java in your ColdFusion applications? What do you typically use it for, or what have you used it for in the past? Finally, which of the techniques above do you typically use, and why?

COMMENTS

  • By Todd - 12:12 PM on September 8, 2003   Reply

    I find myself exploring more and more with #3 (using createObject()).

  • By Massimo Foti - 12:16 PM on September 8, 2003   Reply

    I am using Java in CFML more and more. I started with things than in CF 5 required COM objects or external programs, like image manipulation. Now I am also using it for advanced XML/XSL/DOM stuff and file I/O (including zip files).I never felt the need to use CFX and I only evaluated a few JSP tags, mainly for testingThe italian CFUG website has a section dedicated to Java/CFML integration:http://www.cfmentor.com/code/index.cfm?action=ls_script&cat=14

  • By paulH - 12:22 PM on September 8, 2003   Reply

    i use createObject w/cfscript for i18n functions for locales that cf doesn’t support, interface with 3rd party apps (like arcIMS via its java connector, inetAddressLocator, etc.) or whenever i need something thats faster or easier in java. daily, i guess.you can directly embed java in cfscript? can you post some examples?

  • By Sam - 12:42 PM on September 8, 2003   Reply

    I find myself using createObject a lot in response to webforum questions, but I hardly ever use Java in our boring production apps. The only production instance is a CFX tag for spell checker.What is the difference between #3 and #4? By direct embedding do you mean the forName() thing? I’ve done that once when we needed to upload files on a shared host that had cffile disabled, but would have rather the host enabled cffile and just implemented directory security properly.

  • By paulH - 12:53 PM on September 8, 2003   Reply

    reflection’s a bear for anything complicated.

  • By Christian Cantrell - 1:16 PM on September 8, 2003   Reply

    I just added the word “custom” to #3 to make it clearer. What I mean is that you don’t have to use the CustomTag or the JSP custom tag interfaces to use Java from CF. You can just write any types of objects you want, and as long as they are in your classpath, you can instantiate them using CFOBJECT or createObject. #4 refers to using the JDK directly from ColdFusion (which is essentially using introspection) without writing your own Java files.Christian

  • By Michael Buffington - 2:23 PM on September 8, 2003   Reply

    I used to do a lot of Java CFX tags, but have more recently dropped that in favor of using createObject in CFSCRIPT. I love the Java support in CFMX, and I feel like I have so much more unhindered access to Java assets in CFMX than I ever have.

  • By Tarantor - 3:04 PM on September 8, 2003   Reply

    … and I have just bought a new book “Java for ColdFusion Developers” from Eben Hewitt and it seems not bad. :-) And I am just converting my image tools into Java based solutions. As you know CFX_Image etc. sucks and I think JAI or other opportunities rocks! :)

  • By Jade - 7:17 PM on September 8, 2003   Reply

    Just like the previous comment, I am using Java to manipulate images and also to convert between file types (pdf, etc).I use CFScript for this, as I found it to be a lot easier than the other options. I had never used CFX tags in the past because the interface was a little limited.

  • By Sean Corfield - 2:58 PM on September 9, 2003   Reply

    I guess I use #3 most with some #4. If the Java API is complex or ugly, I just wrap it up in a CFC and expose a more CF-friendly interface.BTW, I see Daine has spammed your blog too…

  • By Buy.com - 7:12 PM on December 10, 2003   Reply

    Just like the previous comment, I am using Java to manipulate images and also to convert between file types (pdf, etc).I use CFScript for this, as I found it to be a lot easier than the other options. I had never used CFX tags in the past because the interface was a little limited.

  • By rlash - 11:05 PM on August 16, 2004   Reply

    I found these blogs following links on a java image manipulation search. I am trying to find some java manipulation resources to use in CFC.Any links, resources info appreciated. I am not looking for a pricey solution but something open source that I can use.Thanks

  • By bullcatt - 2:39 PM on September 9, 2004   Reply

    I would like to know, when and why are the best times to use java in a cold fusion page

ADD A COMMENT