ITIG ACRL/NEC Information Technology Interest Group Homepage
ACRL/NEC Home | ITIG Home | ITIG Officers | Join ITIG | ITIG-L
TechCorner | Annual Reports | Meeting Minutes | Programs


ITIG Tech Corner
"Allaire's Cold Fusion: It Can Make a Webmaster's Life Easier"

Olga Verbeek, Salve Regina University
September/October 2000

 

Introduction

Nuclear physics jokes aside, ColdFusion is a powerful Web development tool for creating interactive, database-driven Web solutions. With ColdFusion, you can dynamically serve Web pages and create cross-platform, dynamic Web applications that exchange information from databases, templates, files, and users. And it's all done with simple tags that look a lot like HTML. ColdFusion integrates Hypertext Markup Language (HTML), Extensible Markup Language (XML), Structured Query Language (SQL), databases, and ColdFusion's tag-based scripting language (CFML) to enable even the intermediate-level Web developer to create versatile, sophisticated Web sites.

ColdFusion is compatible with open standards and has integrated support for all Internet technologies, including Java, JavaScript, DHTML, and practically everything else. ColdFusion, proprietary software developed by the Allaire Corporation, is similar in functionality to Microsoft's Active Server Pages (ASP), although its friendly tag-based markup language makes it faster and easier to get started. If your site requires continuous updates, variations, daily news, events and the like, ColdFusion can save you immeasurable time. Developing with ColdFusion involves a relatively small learning curve, which helps to make it one of the fastest-growing Web technologies. The list of things you can do with ColdFusion is long, but its primary strength is that it enables users to search and select data from your databases, add records, perform transactions, customize the content of your site, and ! ! other such database-driven solutions.

 

Various ColdFusion Products

ColdFusion Server 4.5, the full version of ColdFusion, is on par with the most robust server applications out there. It has been designed to deliver top-notch performance from the smallest Access database on a basic server, to enterprise-level performance using multiple servers in tandem (clustering) and is available for Windows, Linux, Solaris, and the HP-UX operating systems.

ColdFusion Express is a freely available, pared-down version of ColdFusion. This program was used for the examples in this presentation.

ColdFusion Studio is tightly integrated with ColdFusion Server. ColdFusion Studio provides visual programming, database, and debugging tools for building sophisticated Web applications.

 

Some ColdFusion Basics

All ColdFusion documents must have a .cfm extension in order for the ColdFusion tags to work. The .cfm extension triggers the Web server to pass a request to the ColdFusion Application Server, which looks for and processes all ColdFusion operations before it returns a page. The ColdFusion Application Server is the software that runs on the Web server and handles all ColdFusion requests, processes them, and returns HTML and whatever other client-side technologies are present. In a nutshell, here's how it works:

  1. A user sends an HTTP request for a ColdFusion page.
  2. The Web server sends the request to the ColdFusion Application Server.
  3. The ColdFusion Application Server processes all the CFML.
  4. ColdFusion leaves all HTML, scripts, and any other client-side technologies intact, and returns the document to the Web server.
  5. The Web server sends the page back to the user.
Note: If you view the source code of a ColdFusion page, you'll only see HTML - no ColdFusion tags are returned to the user. So, what appear to be static HTML pages are actually ColdFusion templates and application pages at work.

 

ColdFusion and Databases

Perhaps the most important aspect of ColdFusion functionality is its relationship with databases. Instead of having to create HTML documents for every content component on a site, ColdFusion dynamically serves pages from content that resides in a database. ColdFusion can access databases using OLE DB and ODBC, and the full version includes native drivers for Oracle, Sybase, and other databases.

ColdFusion enables you to pass information from a database to the browser of a user connected to your site. This functionality enables you to create highly interactive, customizable sites. For example, you might want users to view a product catalog stored in a database. You might also want your product catalog sorted in a particular order so that the user can easily find information. To do this, you would create a ColdFusion page that extracts your product catalog from a database and displays the results, sorted in the order you chose, in the user's browser.

The page described above uses what's known as a query to pull the information from the database. To create a query in ColdFusion, you use SQL statements. SQL is an acronym for Structured Query Language, and is used to control, define, modify, and query data in a relational database.

In the ColdFusion .cfm page, SQL statements are contained within a CFQUERY block. The generic structure of a CFQUERY block is as follows:

Note that the CFQUERY tag has both a start and an end tag and that all SQL statements (in red) are contained within these tags. The opening CFQUERY tag also contains attributes. Two are required (NAME and DATASOURCE); one is optional (DBTYPE).

Although this is not a course on SQL, the most common and important SQL statement, the SELECT statement is shown in the above example. A SELECT statement must contain at least two clauses: the SELECT clause and the FROM clause. The SELECT clause specifies which database fields to query, while the FROM clause lists the tables where the fields are located. The WHERE clause is optional and allows setting up criteria to be met before a value is selected from the field.

You use the CFOUTPUT tag to output query results. You can also mix both HTML and CFML code within the CFOUTPUT block. Following is an example:

The QUERY attribute in the CFOUTPUT indicates which query is being displayed. In this example the values of field1 display in italics as indicated by the HTML tags.

 

ColdFusion and Headers & Footers

Other .cfm pages can be included within the current .cfm page using ColdFusionís CFINCLUDE tag. The format is as follows:

A common use of this feature is to put web site headers and footers which are the same across many of a web siteís pages into separate .cfm pages and then including them within the page as needed. Changes made within the included pages would automatically be propagated in the pages where they were included (similar to server-side includes).

 

ColdFusion and Forms

Forms are all over the Web, and for good reason -- they enable users to submit input. Forms in ColdFusion are set up the same as they are in any HTML document, but entail ColdFusion operations that turn an ordinary form into an application page, or collection of application pages. Non-ColdFusion forms involve scripts to make the form functional. With ColdFusion, relatively simple tags replace the need for scripts - the Application Server handles that. ColdFusion forms are most often used to enable users to add records to a database, customize pages, and perform searches and other common Web functions.

 

Trying it Yourself

If you wish to try this yourself you will need to install:

  1. A web server on your PC. This is available from Microsoft with Internet Explorer 4 and up. Computers on a network (including the Internet, the largest network) are identified by what's known as an IP address. However, there's one address that can't be used by any computer, and that address is 127.0.0.1. This address is reserved as the loopback address. Simply put, typing http://127.0.0.1 tells the browser not to search for a Web server on the network, but to open its own Web server. This is the address you'll want to use when trying out this product.
  2. ColdFusion - You can download the free Express from www.allaire.com .
  3. Database Application - Microsoft Access is good. You will need to create a database to play with when you try out ColdFusion.

For the ColdFusion server to pass information back and forth between a database and an end-user, you must connect the database to the server. You do this through the administration tools found in the ColdFusion Administrator.

The ColdFusion Administrator was set up when you installed ColdFusion Express, and is accessed through the Start menu or through the ColdFusion 4.0 IDE Service icon in the System Tray (bottom right corner of the task bar). When you start the ColdFusion Administrator, your Web browser opens the administration page. This page (and the other pages that make up the Administrator) is located in the root directory of your Web server, in my case, C:\webshare\wwwroot.

  1. Observe the System Tray. It contains icons informing you that Personal Web Server and ColdFusion server are running. You can access the ColdFusion Administrator from here.
  2. View the screentips for the ColdFusion icons in the System Tray. One icon is associated with the ColdFusion 4.0 IDE Service and the other with the ColdFusion 4.0 server. The ColdFusion Administrator is accessed through the ColdFusion 4.0 IDE Service icon.
  3. Right-click on the ColdFusion 4.0 IDE Service icon and choose ColdFusion Administrator. Your browser opens and displays the ColdFusion Administrator login page. It is through this page that you enter the administration tools.
  4. .In the Password text box, type password and press the ENTER key. The Administration Tools page is displayed in your browser.
  5. Observe the ColdFusion Administrator page. The page contains links to various tools in a menu on the left side of the page. While you'll only use one of the tools, you may want to return to this page later and explore the other tools that are available. You may also want to work through the tutorials included with ColdFusion Express, which are also available from the main Administrator page.

You're now ready to connect your database to the ColdFusion server. Select the ODBC link from the menu on the main Administrator page. Once selected, the ODBC Data Sources Available to ColdFusion page is opened in the browser. It is through this page that you'll link any new database to the ColdFusion server. In addition, you use this page to set database parameters, such as giving the database a data source name and description.

The data source name you give a database will be referenced in your ColdFusion applications. For example, if you want to query data from the bookstore.mdb database, and you gave the bookstore.mdb database the data source name webbooks, your code would reference webbooks, not bookstore.mdb. Why would you give a database a different data source name than its filename? One reason is to give it a more logical, easy-to-understand name. On the other hand, you can stick with the original names.

 

More InformationÖ

ColdFusion Help and book sources from EZ Webdesign:
http://www.ezwebdesign.com/coldfusion.html

ColdFusion Tutorials from CFVault:
http://www.cfvault.com/index.cfm/mode/ContentPage/Element/tutorials_full_index

Very basic tutorials in ColdFusion from the Curry School Of Education,University of Virginia:
http://curry.edschool.virginia.edu/teacherlink/infotech/database/coldfusion/home.html

 

Olga Verbeek
Information Systems Librarian
McKillop Library
Salve Regina University
Newport, RI 02840
verbeeko@salve.edu

Comments Welcome!




© Copyright 1999-2001, ITIG ACRL/NEC Information Technology Interest Group. All Rights Reserved.
Website currently maintained by ITIG Webmaster, Olga Verbeek
ITIG URL: http://www.acrlnec.org/sigs/itig/
Last updated: Monday, April 30, 2001
ACRL/NEC Home
ACRL/NEC Newsletter
Join ACRL/NEC
ACRL Home