Building Dynamic Web Applications with ColdFusion

This section presents an overview of Web application development and a discussion of how the ColdFusion Development System can be used to develop dynamic Web content.

At the end of the section you will find a link to the Macromedia ColdFusion Evaluation Resources Center, which provides a wealth of additional information on dynamic Web application development. You can also download an evaluation copy of the ColdFusion Application Server that you can install locally and use with HomeSite.

As Web content becomes increasingly dynamic, and data-driven sites become the norm, you may decide to explore the opportunities available in Web application development. Corporate intranets and extranets, e-commerce sites, and public sites that publish large document sets are all taking advantage of the greatly increased levels of user support that can be implemented through Web applications.

ColdFusion Web Application Development System offers an easy and cost-effective migration path from static Web pages to dynamic Web content.

The skills you are mastering in HTML and site development are readily transferable to development work in ColdFusion. The HTML page is the medium, and tag-based coding is the language of ColdFusion, so you can begin your investigation of ColdFusion with tools already available in HomeSite.

Defining Web applications

What exactly is a Web application? At its simplest, a Web application is a collection of Web pages that perform some form of real processing. As soon as you start generating dynamic content, interacting with databases, processing user form submittals, sending and receiving email programmatically, performing any conditional processing, managing session and state information, performing real-time credit card authorization, and so on, you have created a Web-based application.

What makes Web application development so different from traditional application development is the Internet itself, and how a Web client interacts with a Web server. These are some of the issues that face Web application developers:

What this all means is that the Web dramatically changes the application development landscape, and therefore traditional application development tools must be replaced with tools designed explicitly to take advantage of the Web, while also providing developers with solutions to these and other problems.

Understanding ColdFusion

ColdFusion is a Web application development system that is designed to extend the functionality of your Web server. The development system is made up of several key components:

ColdFusion functions as a Web page preprocessor on the Web server, allowing you to embed sophisticated commands into your Web page. ColdFusion pages are plain text files that look much like HTML files. The only real difference between HTML files and ColdFusion files is the file extension, ColdFusion files have an extension of CFM. Other than that, whatever you can do in an HTML page, you can do in a CFM page. That, and a whole lot more.

The CFML language is made up tags that provide all sorts of functionality, from database integration, to SMTP and POP support, to COM support, and programming constructs like conditional processing and looping. In addition, there are hundreds of third party add-on tags available, and you can write your own custom tags, too.

How does ColdFusion work? This is the basic process:

  1. A user requests a ColdFusion page (one with a CFM extension). The Web server recognizes the page as being a ColdFusion page, and hands it off to the ColdFusion server for processing.
  2. ColdFusion parses and processes the page, executing any embedded tags and generating dynamic content.
  3. ColdFusion returns the page results (not the page itself) to the Web server, which in turn transmits it back to the user as HTML.

It is important to remember that ColdFusion only processes its own tags, and leaves any other code intact. ColdFusion supports Java, ActiveX, JavaScript, DHTML, VRML, HDML, and many other Web technologies.

Database integration

Database integration is an integral part of any Web-based application. And to demonstrate just how easy it is to write ColdFusion code, here is a simple example of database integration-dynamically generating data-driven page content.

Take a look at the code snippet below. The CFQUERY tag is the ColdFusion SQL integration tag. Here it is being used to send an SQL SELECT statement to a database, but it can be used to execute any SQL statement. The DATASOURCE attribute specifies the ODBC datasource to retrieve the data from and the NAME attribute specifies the name to be used to refer to the query result set.

<CFQUERY DATASOURCE="catalog" NAME="prods">
  SELECT product_id, product_description
  FROM products  ORDER BY product_description

As soon as ColdFusion reaches the end of the SQL query (the closing CFQUERY tag), it executes the SQL statement. It also stores the results in an array named by whatever is specified in the NAME attribute. This example retrieves two fields from a product table.

To display the retrieved data, you would use the CFOUTPUT tag. CFOUTPUT lets you mark a block of code to be processed for each row retrieved by the CFQUERY tag. The code snippet below creates an HTML unordered list (the UL tag), but instead of hard coding the list items, a CFOUTPUT tag is used to dynamically generate the needed LI tags.

<H1>Product List</H1>
  <CFOUTPUT QUERY= "prods">
    <LI>#product_description# (#product_id#)</LI><BR>

Assuming our database table had just three records, this is what the generated HTML would look like:

Product List

And that is all there is to it.

Of course, you could create far more complex and sophisticated SQL statements if required. ColdFusion will even let you dynamically construct SQL statements using variables, IF statements, loops, and other forms of conditional processing. ColdFusion fully supports any and all SQL syntax, including joins, unions, sub-queries, aliases, aggregate functions, and stored procedures. And ColdFusion supports almost every database out there.

CFML support in HomeSite

All CFML tags are available in the Tag Chooser (CTRL+E) you can use the CFML toolbars on the QuickBar to easily insert CFML tags. As with the other supported languages, you can right-click in any CFML tag in Edit mode and select Edit Tag to open the editor for that tag.

CFML tags are color-coded, so they are easily distinguished from other types of tags.

Tag-based programming

Notice that the standard HTML syntax of a tag name followed by attributes is used in CFML. It is much closer to HTML than to JavaScript, VBScript, or a 4GL such as C++ or Java. Notice too, that the requirements for coding the tags are straightforward and intelligible. Even tags that provide very high levels of functionality, such as cfquery and cfoutput, are relatively easy to program.

This follows the principle of encapsulating complexity. This means wrapping procedures like querying data sources and validating form fields in a tag and letting the developer focus on the application's structure and logic.

You can combine these tags and other CFML and HTML elements into Custom Tags and drop them into ColdFusion applications.

Getting Started with ColdFusion

The ColdFusion Evaluation Resource Center at offers resources for both novice and experienced Web developers. You can also download an evaluation copy of the ColdFusion Application Server that you can install and use with HomeSite and your locally installed Web server.

The complete ColdFusion documentation set is installed in your Web server root and you can also download documentation in Adobe Acrobat format by going to