Article

Home » Server-side Coding » ColdFusion Tutorials » Get Shorty: Trim the Fat with ColdFusion
SitePoint Feature Article

About the Author

Kay Smoljak

author_kay Kay is an all-round web developer who has been hacking ColdFusion since 2000. She runs Clever Starfish with her partner Dave and several very demanding cats, and sits on the committee of the Australian Web Industry Association.

View all articles by Kay Smoljak...

Get Shorty: Trim the Fat with ColdFusion

By Kay Smoljak

August 5th, 2009

Reader Rating: Not yet rated

Page: 1 2 3 Next

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:

  1. Click on the Add Server icon—there’s a little yellow plus sign on it.

  2. Select ColdFusion as the server type, and click Next.

  3. Enter a name for the server—this is so it’s recognizable to you. I’ve entered localhost.

  4. Enter the hostname—if you’re running the default setup, it’s localhost too.

  5. Enter the port—the default for the built in development setup is port 8500.

  6. 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).

  7. Enter the RDS password you specified when installing ColdFusion. Click Next.

  8. 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.

  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.

  10. Select the version of ColdFusion installed from the drop down box—9.0.x.

  11. 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.

The Servers tab, showing our local server

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.

  1. 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.

  2. 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.

  3. From the Import wizard, drill down to ColdFusion -> Import Existing Projects, and click Next.

  4. 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.

Selecting the project in the Import ColdFUsion Project dialog

The project will now be listed in your Navigator panel. The last step is to associate the project with our server.

  1. Right click on the project name and select Properties.

  2. Select ColdFusion Server Settings from the left hand side of the dialog.

  3. Select your local development server from the drop-down box of servers, and click OK.

Selecting a server

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links