Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Jeff McDowell and Joel Hill and Jonathan Rowny and Shawn Grigson and Jonathan Dowdle and Matt Vickers and Christian Ready and Asher Snyder and Clark Valberg and Oscar Arevalo and David Bainbridge and Josh Siok
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Jeff McDowell@jeff_s_mcdowell ) , Joel Hill@Jiggidyuo ) , Jonathan Rowny@jrowny ) , Shawn Grigson@shawngrig ) , Jonathan Dowdle@jdowdle ) , Matt Vickers@envex ) , Christian Ready@christianready ) , Asher Snyder@ashyboy ) , Clark Valberg@clarkvalberg ) , Oscar Arevalo@oarevalo ) , David Bainbridge ( @redwhitepine ) , and Josh Siok@siok )

Java Exploration in ColdFusion:

By Ben Nadel on
Tags: ColdFusion

I was looking at Dan G. Switzer, II's post about parsing a URI when it got me thinking: Java has so much awesome stuff, what do they have for URLs. It turns out, there is a class that is all about parsing out URL information. I took it for a spin.

First, I created a URL:

  • <!--- Set the URL. --->
  • <cfset strUrl = (
  • "" &
  • "freshman-girls/brunettes.cfm" &
  • "?single=true&min_hotness=7" &
  • "##getstarted"
  • ) />

I tried to put as much info into the URL as I could to see how it all got parsed out. Then, I created a URL object and initialized it with the given Url:

  • <!--- Create a Java URL. --->
  • <cfset jUrl = CreateObject( "java", "" ).Init(
  • strUrl
  • ) />

The has a bunch of classes that can all be found in the Java 2 documentation. Here is what each of them does when called on the previously created jUrl object:




















jUrl.toExternalForm() brunettes.cfm?single=true&min_hotness=7#getstarted

That's some pretty cool stuff. I guess most of this is available via the CGI variables, but it's nice to know you can create objects. You can all get the content of the target page of the given URL in this method, but I haven't had time to play with that yet.

Tweet This Groovy post by @BenNadel - Java Exploration in ColdFusion: Thanks my man — you rock the party that rocks the body!

Reader Comments

Those Java methods realy saves time! I had to convert punycode to IDN. It was very simple when I found the right class (borowed a bit from your code..):

  • <cfset strUrl = "" />
  • <!--- Create a Java URL. --->
  • <cfset jUrl = CreateObject( "java", "" ).toUnicode(strUrl) />
  • <cfoutput>
  • #jUrl#
  • </cfoutput>