Article
Get Shorty: Trim the Fat with ColdFusion
Tired of the same old URL shorteners like TinyURL, tr.im or bit.ly? Ever wished you could run your very own URL shortener? In ColdFusion, it’s probably easier than you think. To demonstrate just how powerful and easy to use ColdFusion is, we’re going to build our own simple URL shortener from scratch. In this article, we’ll start out with a basic set of functions—creating shortened links, and expanding them. Don’t forget to try the quiz when you’ve finished reading!
To follow along, you’ll need to download and install the ColdFusion 9 and ColdFusion Builder betas and install them on your development machine. ColdFusion 9 is also available for Linux, and it is possible (with some tweaking) to install ColdFusion Builder—see this tutorial at Compound Theory for details. You’ll also need to grab the code archive for this tutorial.
Before we start
This tutorial assumes that you have ColdFusion 9 beta running on localhost, on port 8500, using the stand-alone, built-in development server. If you’ve installed ColdFusion on a machine other than localhost, or are using IIS or Apache instead of the stand-alone development server, or are using a J2EE server configuration, you’re going to need to change the server paths mentioned in the code listings.
We’re also going to assume that you have ColdFusion Builder installed on the same localhost machine. If you already have the Eclipse IDE on your machine (including Flash Builder or Flex Builder) and have installed ColdFusion Builder as a plugin, you’ll need to make sure you’re in the ColdFusion perspective: from the Window menu, select Open Perspective > Other > ColdFusion.
Before we start coding, we’re going to tell ColdFusion Builder which ColdFusion server we will be working with. We’ll configure this using the Servers tab at the bottom of the ColdFusion Builder window. There are quite a few steps to follow here, which I’ve broken down for you below:
- Click on the Add Server icon—there’s a little yellow plus sign on it.
- Select ColdFusion as the server type, and click Next.
- Enter a name for the server—this is so it’s recognizable to you. I’ve entered localhost.
- Enter the hostname—if you’re running the default setup, it’s localhost too.
- Enter the port—the default for the built in development setup is port 8500.
- Enter the RDS User Name, which is always admin, unless you specified a different username when you installed the server (this is usually only the case if you’re running on a J2EE server configuration).
- Enter the RDS password you specified when installing ColdFusion. Click Next.
- Browse for your Server Home. This is the directory where ColdFusion was installed—on Windows, it will probably be C:\ColdFusion9; on the Mac, /Applications/ColdFusion 9.
- You might also need to browse for your Document Root. This is your web root—on a default Windows installation, it will probably be C:\ColdFusion9\wwwroot; on the Mac, it’s at /Applications/ColdFusion9/wwwroot.
- Select the version of ColdFusion installed from the drop down box—9.0.x.
- Click Finish.
ColdFusion Builder will verify these details and connect to the server. If all went well, you should see the server in the Servers tab. You can start and stop the server and access its ColdFusion Administrator panel from this tab.
![]()
ColdFusion Builder works with projects. We could create a new project now, and associate it with our development server, but to make things easier for you we’ve included all the code in a downloadable project which we’re now going to import.
- Download the sample zip file and extract the folder into your ColdFusion web root. Change the name of the folder to URLS now, if needed.
- The navigator panel on the left hand side of the screen shows the files in your current project. Right-click in the Navigator and select Import.
- From the Import wizard, drill down to ColdFusion -> Import Existing Projects, and click Next.
- Browse for the folder you just extracted.
ColdFusion Builder will scan the folder and look for any project files, which will then be listed in the Project List below. Check the box next to our URLs project, and then click Finish.
![]()
The project will now be listed in your Navigator panel. The last step is to associate the project with our server.
- Right click on the project name and select Properties.
- Select ColdFusion Server Settings from the left hand side of the dialog.
- Select your local development server from the drop-down box of servers, and click OK.
![]()
Kay is an all-round web developer who has been hacking ColdFusion since 2000. She runs