Cold Fusion: Turning Web Pages Into Web Applications

Anyone can create a web page. HTML is simple enough to learn, and new editors and authoring tools can even partially eliminate the need for that. But static HTML pages have had their day. Now that the web has proven itself as a solid platform for publishing and collecting diverse types of data, organizations are migrating en masse from static web sites to full blown web applications. Whether it be Intranets, Extranets, public internet sites, or high visibility commercial sites, web based applications are now a fact of Internet life. To stay current and in demand, web site developers must master the skills needed to create these applications, and must do so quickly. This article describes one of the most popular technologies currently being used to create web applications - Cold Fusion from Allaire Corporation.

Defining "Web Applications"
Understanding Cold Fusion
Database Integration
All the acronyms you'd want, and then some
Building Complete Applications
The Development Environment - Cold Fusion Studio
Conclusion

Defining "Web Applications"  
So, what exactly is a "web application"? Well, 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 submissions, sending and receiving e-mail programmatically, performing any conditional processing, managing session and state information, performing real-time credit card authorization, and so on, you've created a web based application.

What makes web application development so different from traditional application development is the Internet itself, and how web clients interact with web servers. Some of the issues that web application developers have to deal with are:

What this all means is that the web has dramatically changed 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 Cold Fusion  
Cold Fusion 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:

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

The CFML language is made up of over 50 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.

So, how does Cold Fusion work its magic? Well, it goes something like this:

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

It is important to remember that Cold Fusion only processes its own tags, and leaves any other code intact. Therefore, Cold Fusion supports any and all client technologies, including Java, ActiveX, JavaScript, DHTML, VRML, HDML, and whatever else you'd care to throw at it.

Database Integration  
Database integration is an integral part of any web based application. And so to demonstrate just how easy it is to write Cold Fusion code, let's take a look at 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 Cold Fusion SQL integration tag. Here it is being used to send a 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
</CFQUERY>

As soon as Cold Fusion reaches the end of the SQL query (the </CFQUERY> tag) it executes the SQL statement, and stores the results in an array named by whatever is specified in the NAME attribute. This example retrieves two fields from a products table.

To display the retrieved data you'd 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 a standard 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>
<UL>
<CFOUTPUT QUERY= "prods">
<LI>#product_description# (#product_id#)
</CFOUTPUT>
</UL>

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

<H1>Product List</H1>
<UL>
<LI>Gadget (G14)
<LI>Widget (WD10)
<LI>Widget Plus (WP01)
</UL>

And that's all there is to it.

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

All the Acronyms You'd Want, and Then Some  
But Cold Fusion does more than provide database integration. Some of the many other technologies and protocols supported include:

And for the really adventurous, the next version of Cold Fusion will support XML, CORBA, server-side JavaBeans, and much more.

Building Complete Applications   
As the complexity of your applications grows, so will your need for a development tool that can create complete, reliable, and robust applications. Cold Fusion provides you with the tools needed to create these applications, and addresses all the concerns shared by web application developers the world over.

Scalability - Cold Fusion is highly scalable, as proven by the number of high-visibility commercial Cold Fusion powered web sites, many of which are handling millions of hits a day. Cold Fusion is not a CGI application, it is a multi-threaded web server extension (ISAPI, NSAPI, WSAPI, Apache) and is designed to handle massive loads. And when application load exceeds the capabilities of the hosting server, Cold Fusion applications can be setup to run on multiple hosts seamlessly and transparently.

Security - Cold Fusion is designed to take advantage of any and all existing security systems, including the underlying NOS security scheme, and any web server based security.

Extensibility - Cold Fusion supports all the popular web based technologies and products (for example, HDML, Verity, CyberCash, ICVerify, OpenMarket). You can also extend CFML by writing your own tags in C, C++, CFML, or plug in any COM and DCOM objects as needed. Numerous third party add-on products are now available to further extend Cold Fusion capabilities.

Rapid Development - As seen above, Cold Fusion code is incredibly easy to write. CFML was designed to facilitate rapid prototyping, development, and deployment.

The Development Environment - Cold Fusion Studio   
As explained earlier, Cold Fusion pages are plain text files, just like HTML files. As such, you can write Cold Fusion applications in any text or HTML editor.

However, the best tool for creating Cold Fusion applications is "Cold Fusion Studio", the Cold Fusion IDE. Studio is not an authoring tool, it does not try to write code for you, nor does it hide the underlying code from you. Rather, Studio is a programmers editor, and it is designed to work the way you work. Studio features include:

And that's just the tip of the iceberg. Cold Fusion Studio is without question the ideal editor for both HTML and CFML development.

Conclusion   
Web applications are more than a craze or a passing fad. New web applications are cropping up every day, both on the public Internet, and on private sites. Cold Fusion provides developers with all the tools need to design, develop, and deploy solid and scalable web based applications. By supporting open standards and best-of-breed technologies, Cold Fusion allows developers to create applications as varied as the needs they serve, while ensuring compatibility and reliability for years to come.

For more information, and to download an evaluation version of Cold Fusion, visit the Allaire web site at http://www.allaire.com. In know time at all, your web site will be powered by Cold Fusion.