-
Developing Web Applications with ColdFusion ColdFusion 4.
-
Copyright Notice © 1999 Allaire Corporation. All rights reserved. This manual, as well as the software described in it, is furnished under license and may be used or copied only in accordance with the terms of such license. The content of this manual is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Allaire Corporation.
-
Contents Preface: Welcome to ColdFusion ..................................................................xv Intended Audience.........................................................................................................................xvi Welcome to the ColdFusion 4.5 Web Application Server ...........................................................xvi Products and System Requirements ...........................................................................................
-
iv Developing Web Applications with ColdFusion ColdFusion Server .....................................................................................................................6 ColdFusion Administrator........................................................................................................6 Data sources ..............................................................................................................................7 How ColdFusion Server Works ...........................
-
Contents Creating Table Joins........................................................................................................................40 Building Flexible Search Interfaces ...............................................................................................40 Code Review ............................................................................................................................41 Returning Query Results to the User...................................................
-
vi Developing Web Applications with ColdFusion Access to generated content...................................................................................................84 Installing Custom Tags ...................................................................................................................85 Local tags..................................................................................................................................85 Shared tags.......................................
-
Contents Array Functions.............................................................................................................................111 About Structures ...........................................................................................................................113 Structure notation .................................................................................................................113 Creating and Using Structures.................................................
-
viii Developing Web Applications with ColdFusion Chapter 11: Indexing and Searching Data .................................................149 Searching a ColdFusion Web Site................................................................................................150 Advantages of using Verity ...................................................................................................150 Online Verity training ....................................................................................
-
Contents Choosing a client variable storage method.........................................................................189 Managing Client State in a Clustered Environment ..................................................................190 Using Client State Management..................................................................................................190 Creating a client variable ......................................................................................................
-
x Developing Web Applications with ColdFusion Chapter 14: Managing Files on the Server .................................................219 Using CFFILE ................................................................................................................................220 Uploading Files .............................................................................................................................220 Resolving conflicting file names ...............................................
-
Contents Chapter 17: Application Security ................................................................263 ColdFusion Security Features......................................................................................................264 Remote Development Services (RDS) Security ..........................................................................264 Overview of User Security ............................................................................................................
-
xii Developing Web Applications with ColdFusion CCFXQuery Class ..........................................................................................................................295 Class members.......................................................................................................................295 CCFXQuery::AddRow............................................................................................................296 CCFXQuery::GetColumns..................................
-
Contents Invoking Component Objects......................................................................................................327 Coding guidelines..................................................................................................................327 Calling methods ....................................................................................................................327 Calling nested objects ............................................................................
-
xiv Developing Web Applications with ColdFusion
-
Preface Welcome to ColdFusion This manual describes the process of developing Web applications using ColdFusion. In the first six chapters, you can follow the instructions presented to learn how to create basic ColdFusion applications. Then, chapters seven through 17 cover various topics of interest in enhancing your applications. Finally, chapters 18 through 21 explain how to extend ColdFusion’s capabilities.
-
xvi Developing Web Applications with ColdFusion Intended Audience This manual is particularly useful for Web application developers who are new to ColdFusion. In particular, Chapters 1 through 6 provide instructions for creating a basic ColdFusion application. If you are somewhat familiar with ColdFusion, but want to learn more about a particular topic such as sending and receiving email, refer to Chapters 7 through 17.
-
Preface xvii Products and System Requirements ColdFusion has been fully tested on the following platforms and with the following configurations. ColdFusion Server 4.5 Enterprise Edition for Windows • Windows NT 4.0 SP4+ • Intel Pentium or above • 150 MB hard disk space • 128 MB RAM (256 MB recommended for clustering) ColdFusion Server 4.5 Enterprise Edition for Solaris • SPARC Solaris 2.5.1, 2.
-
xviii Developing Web Applications with ColdFusion ColdFusion Studio 4.5 • Windows 95/98/NT4 • Intel Pentium or above • 35 MB hard disk space • 32 MB RAM (64 MB recommended) New Features in ColdFusion 4.5 A wide range of new features are available in ColdFusion 4.5. New visual tools Universal File Browser — Access all your files from a single explorer that integrates access to the Windows file system, ColdFusion RDS servers, and FTP servers.
-
Preface xix Enhancements to CFML Object Scripting — Instantiate and script objects using CFML script in addition to the CFOBJECT tag easier integration with distributed object middleware such as COM and CORBA. Structured Exception Handling — Exception handling now offers hierarchical exception handling that supports both greater customization and greater access to internal exceptions. String Conversion Functions — Convert strings quickly and easily to be compatible with Java Script and XML standards.
-
xx Developing Web Applications with ColdFusion Scriptable Performance Metrics — Track key server metrics at run time through your own scripts for intelligent diagnosis of performance bottlenecks of stability problems in your applications. Performance Debugging Data — Access detailed debugging information on the performance of each individual page included in an application page that is being debugged.
-
Preface xxi OS Server Sandbox Security — Secure shared hosting environments more easily by creating Server Sandboxes with Windows NT security. OS Server Sandboxes process all requests under the privileges of a designated Windows NT user account (Enterprise Edition for Windows only). Enhanced Advanced Security — Secure CFML functions and enable CFML code segments to be executed using the run-time security permissions of a designated user.
-
xxii Developing Web Applications with ColdFusion About ColdFusion Documentation ColdFusion documentation is designed to provide support for all components of the ColdFusion development system. Both the print and online versions are organized to allow you to quickly locate the information you need. In addition to the book set, the documentation is provided in two other formats: • HTML — Browser-based Help references.
-
Preface xxiii Using ColdFusion Studio Documents everything you need to know about using ColdFusion Studio, including features like projects, source control integration, as well as the Studio workspace and interface. ColdFusion Quick Reference Guide A valuable quick reference to CFML tags, functions, and variables. ColdFusion Server online documentation To view the HTML documentation, open the following URL: http://127.0.0.1/ cfdocs/dochome.htm.
-
xxiv Developing Web Applications with ColdFusion Documentation conventions When reading, please be aware of these formatting cues: • Code samples, filenames, and URLs are set in a monospaced font • Notes and tips are identified by bold type • Bulleted lists present options and features • Numbered steps indicate procedures • Tool button icons are generally shown with procedure steps • Menu levels are separated by the greater than (>) sign • Text for you to type in is set in italics Getting Answers One of
-
Preface xxv Technical support Telephone support is available Monday through Friday 8 A.M. to 8 P.M. Eastern time (except holidays) Toll Free: 888.939.2545 (U.S. and Canada) Tel: 617.761.2100 (outside U.S. and Canada) For complete details about Allaire Product Support options, please refer to the Allaire Support pages on the Allaire web site: http://www.allaire.com/support. Postings to the ColdFusion Support Forum (http://forums.allaire.com) can be made any time. Sales Toll Free: 888.939.2545 Tel: 617.
-
xxvi Developing Web Applications with ColdFusion
-
CHAPTER 1 Chapter 1 Introduction to ColdFusion This chapter explains the difference between creating static Web pages with HTML and creating dynamic applications with ColdFusion. It also describes what ColdFusion is and how it works. Contents • A Quick Web Overview....................................................................................... 2 • What You Should Already Know........................................................................ 2 • What is ColdFusion?......................
-
2 Developing Web Applications with ColdFusion A Quick Web Overview Over the last few years, the Web has changed from being simply a collection of static HTML pages to an application development platform. Rather than offering a space where organizations can merely advertise goods and services, similar to traditional yellow pages directories, companies conduct business ranging from ecommerce to managing internal business processes.
-
Chapter 1: Introduction to ColdFusion 3 What is ColdFusion? ColdFusion lets you create page-based Web applications using ColdFusion Markup Language (CFML), the tag-based language you use to create server-side scripts that dynamically control data integration, application logic, and user interface generation. ColdFusion Web applications can contain XML, HTML, and other client technologies such as CSS and JavaScript.
-
4 Developing Web Applications with ColdFusion Rapid development The ColdFusion development platform enhances the speed and ease of development through the following features: • A tag-based server scripting language that is powerful and intuitive. • Two-way visual programming and database tools. • Remote interactive debugging for quickly identifying and fixing problems. • Web application wizards to automate common development tasks. • Source control integration to enable team development.
-
Chapter 1: Introduction to ColdFusion 5 Complete security ColdFusion provides a foundation for building secure applications through the following features: • Integration with existing authentication systems including Windows NT domain and LDAP directory servers, and proprietary user and group databases. • Advanced access control so that server administrators can control developers’ access to files and data sources. • Support for existing database security.
-
6 Developing Web Applications with ColdFusion ColdFusion Studio ColdFusion Studio is the development environment for ColdFusion Server. It offers visual development tools, including dynamic page previews using your Web browser, an interactive debugger, a query builder, an expression builder, project management and source control tools, and many other productivity enhancements. To learn more about ColdFusion Studio, see Using ColdFusion Studio.
-
Chapter 1: Introduction to ColdFusion 7 Data sources ColdFusion applications may interact with any database that supports the ODBC standard. However, ColdFusion is not limited to ODBC data sources. You can also retrieve data using OLE-DB, native database drivers, or directory servers that support the Lightweight Directory Access Protocol (LDAP). Data can also be retrieved from mail servers that support the Post Office Protocol (POP), and which is indexed in Verity collections.
-
8 Developing Web Applications with ColdFusion
-
CHAPTER 2 Chapter 2 Writing Your First ColdFusion Application This chapter guides you through the ColdFusion development process as you create a ColdFusion application page, save it, and view it in a browser. Contents • The Development Process............................................................................... 10 • Writing Code..................................................................................................... 10 • Saving Application Pages................................
-
10 Developing Web Applications with ColdFusion The Development Process Whether you are creating a static HTML page or a ColdFusion application page, you follow the same iterative process: • Write some code. • Save the code to a document or page. • View the page in a browser. • Modify the page. • Save the page again. • View it in a browser. • and so on...
-
Chapter 2: Writing Your First ColdFusion Application 11 Saving Application Pages Instead of saving pages with an HTM or HTML file extension, you save ColdFusion application pages with a CFM or CFML extension. By default, the Web server knows to pass a page that contains a CFM extension to the ColdFusion Server when it is requested by a browser. Save ColdFusion application pages underneath the Web root or another Web server mapping so that the Web server can publish these pages to the Internet.
-
12 Developing Web Applications with ColdFusion Compare the code that was returned to the browser with what you originally created. Notice that the ColdFusion comments and CFML tags are processed, but do not appear in the HTML file that’s returned to the browser.
-
Chapter 2: Writing Your First ColdFusion Application 13 Variables A Web application page is different from a static Web page because it can publish data dynamically. This involves creating, manipulating, and outputting variables. A variable stores data that can be used in applications. As with other programming languages, you’ll set variables in ColdFusion to store data that you want to access later. And you’ll reference a range of variables to perform different types of application processing.
-
14 Developing Web Applications with ColdFusion Adding More Variables to the Application Applications can use many different variables. For example, the calldept.cfm application page can set and display values for department, city, and salary. To modify the application: 1. Return to the file calldept.cfm in ColdFusion Studio, 2.
-
CHAPTER 3 Chapter 3 Querying a Database This chapter describes how to retrieve data from a database, work with query data, and enable debugging in ColdFusion applications. You will learn how to use the ColdFusion Administrator to set up a data source and enable debugging, use the CFQUERY tag to query a data source, and use the CFOUTPUT tag to output the query results to a Web page. Contents • Publishing Dynamic Data................................................................................
-
16 Developing Web Applications with ColdFusion Publishing Dynamic Data A Web application page is different from a static Web page because it can publish data dynamically. This can involve querying databases, connecting to LDAP or mail servers, and leveraging COM, DCOM, CORBA, or Java objects to retrieve, update, insert, and delete data at runtime — as your users interact with pages in their browsers.
-
Chapter 3: Querying a Database 17 Data can be organized in multiple tables. This type of data structure is known as a relational database and is the type used for all but the simplest data sets. From this basic description, a few database design rules emerge: • Each record should contain a unique identifier, known as the primary key. This could be an employee ID, a part number, or a customer number.
-
18 Developing Web Applications with ColdFusion Understanding Data Sources A database is a file or server that contains a collection of data. A data source is a pointer from ColdFusion to a specific database. You add data sources to your ColdFusion Server so that you can point to the databases that you want to connect to from your ColdFusion applications. Open Database Connectivity (ODBC) ODBC is a standard interface for connecting to a database from an application.
-
Chapter 3: Querying a Database 19 Adding Data Sources You add data sources in the ColdFusion Administrator to define connection requirements for database access. When you add a data source, you assign it a name so that you can reference it within tags such as CFQUERY on application pages to query databases. During a query, the data source tells ColdFusion which database to connect to and what parameters to use for the connection. To add a data source: 1. Start the ColdFusion Administrator.
-
20 Developing Web Applications with ColdFusion The data source is added to the data source list. 9. Locate CompanyInfo in the data source list. 10. Choose Verify to run the verification test on the data source. If the data source was created, you should see this message: The connection to the data source was verified successfully. For more information about managing data sources, See Administering ColdFusion Server.
-
Chapter 3: Querying a Database 21 • Performs SQL commands that are enclosed within the block. • Returns query variable values to the page. CFQUERY tag syntax You’ll type SQL here In this example, the query code tells ColdFusion to: • Use the CompanyInfo data source to connect to the company.mdb database. • Store the retrieved data in the query variable EmpList.
-
22 Developing Web Applications with ColdFusion When the database processes the SQL, it creates a data set that is returned to ColdFusion Server. ColdFusion places the data set in memory and assigns it the name that you defined for the query in the begin CFQUERY tag. You may reference that data set by name using the CFOUTPUT tag further down on the page. Basic SQL Syntax elements The following sections present brief descriptions of the main SQL command elements.
-
Chapter 3: Querying a Database 23 Operators These specify conditions and perform logical and numeric functions: Basic SQL Operators Operator Description AND Both conditions must be met, such as Paris AND Texas OR At least one condition must be met, such as Smith OR Smyth NOT Exclude the condition following, such as Paris NOT France = Equal to <> Not equal to < Less than > Greater than <= Less than or equal to >= Greater than or equal to + Addition - Subtraction / Division * Mul
-
24 Developing Web Applications with ColdFusion Building Queries As discussed earlier in this chapter, you build queries using the CFQUERY tag and SQL. To query the table: 1. Create a new application page. 2. Edit the page so that it appears as follows:
Employee List Employee List
SELECT FirstName, LastName, Salary, Contract FROM Employees 4 4 4 4 3.
-
Chapter 3: Querying a Database 25 Query Notes and Considerations When creating queries to retrieve data, keep these guidelines in mind: • Enter the query NAME and DATASOURCE attributes in the begin CFQUERY tag. • Surround attribute settings with double quotes("). • Reference the query data by naming the query in the CFOUTPUT tag later on the page. • Make sure that a data source exists in the ColdFusion Administrator before you reference iit n a CFQUERY tag.
-
26 Developing Web Applications with ColdFusion 4 4 #FirstName#, #LastName#, #Salary#, #Contract#