Article
Get Started with ColdFusion
ColdFusion MX is the newest version of an already fantastic product developed by Macromedia, arguably the biggest and best producer of Web software out there. CFMX, as it’s commonly referred to, is built on top of J2EE (Java 2 Enterprise Edition), and as a result, is much more robust that previous versions of ColdFusion. If you are wondering whether or not you should upgrade that old copy of 3.1 you still have lying around, the answer is a resounding “yes!”
If you’re just starting out, you probably have a bunch of questions. “Just what is ColdFusion? Do I need to know Java since it is built on J2EE? Why should I use CFMX instead of ASP or other free scripting language?” Let me answer these questions one at a time:
- First of all, ColdFusion MX is a fully functional application server. CFMX will work in conjunction with most popular Web server software available, including Apache, IIS and Deerfield Website. Think of it like this: let’s say you use IIS. In this scenario IIS will act as the batter in a baseball game. The pitcher is a Web user and ColdFusion is the catcher.
In a typical “game”, the user “pitches” an http request for an html page and the batter (that’s the Web server software) hits the request back to the user. With CFMX, a user “pitches” a request for a ColdFusion file. The Web server steps back and let’s the catcher (ColdFusion) take the CFML request and pass it back to the user. I know this analogy is a bit odd but it usually helps illustrate where CFMX fits into the picture.
Secondly, ColdFusion is a powerful server-side scripting language. And believe me, it’s as robust as any language out there. This language consists of tags similar to HTML tags, and FUNCTIONS similar to those found in Visual Basic.
- Third in this line of questions is “Why should I use CFMX instead of another free scripting language?”. I believe that Ben Forta answered that question with a bang in a recent issue of ColdFusion Developer’s Journal. The short version is “you get what you pay for” and CFMX, while it’s not cheap, does deliver a boat-load of features that would cost you many times the price of CFMX in another “free” language.
- Do you need to know Java to use CFMX? No. CFML puts a simple and easy to use language between you and cumbersome Java.
Ok, enough already! Let’s get coding!
I’ve already said that CFML is similar to HTML, but what’s the difference between HTML and CFML? Simple. All ColdFusion tags start with the letters “CF”, allowing you to tell what’s static HTML and what’s ColdFusion code. When ColdFusion reads a CFML page and comes across a ColdFusion tag, it performs the specified task, and returns HTML to the end user. One of the reasons that CFML is so powerful is that it works perfectly with existing HTML. You may embed CF tags into your static HTML and even use ColdFusion to write HTML code for you in many cases. Let’s give it a try.
Lesson 1: The Simple Art of CFML
Let’s start this off with perhaps the most basic and heavily used ColdFusion tag:
<CFOUTPUT></CFOUTPUT>
The “cfoutput” tag allows tells ColdFusion Server to “output” or display data between these tags. By itself, <CFOUTPUT> is useless, but if you combine it with double pound-signs (##), it becomes the basis for the CFML language structure. A completed output tag would appear something like this:
<CFOUTPUT>#VariableName#</CFOUTPUT>
Note: You cannot place cfoutput tags inside other cfoutput tags as a rule. If you do, you will receive an error to tell you that you have invalidly nested cfoutput tags. There is a way and reason to do this, but it goes beyond the scope of this simple tutorial.
Now, let’s produce a simple output. With most programming languages. you always seem to learn a “Hello World” script first, so let’s start with this:
- Make sure that you have installed CFMX.
- Be sure that ColdFusion MX Service is running.
- Create a new folder named Lesson1 under the Webroot of the CFMX Server. C:\CFUSIONMX\WWWROOT\LESSON1
- Open Cold Fusion Studio or another of your favorite text editors. I recommend ColdFusion Studio or Homesite for this function. You can also use Dreamweaver MX in code-view. This lesson will not refer to any of the visual CFML in that application.
- Create a new blank CFML page. It will look the same as a blank HTML document.
- Save this file into your new folder as INDEX.CFM
- In between the
<BODY></BODY>tags, just as you would in HTML, enter the following code:<CFSET MyWorld = ‘Hello World’>
<CFOUTPUT>#MyWorld#</CFOUTPUT> - View the page by opening your browser and entering your IP address (127.0.0.1 in most cases), followed by port 8500 and the folder Lesson1. It should appear like this:
http://127.0.0.1:8500/Lesson1/
Great! Now, let’s break this code sample down:
Jack Poe (