Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at BFusion / BFLEX 2010 (Bloomington, Indiana) with:

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

Hey Ben....
Thanks for this. Saved me a lot of coding time. Keep up the good work.

See you at CFUnited 09

Reply to this Comment

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>

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.