What is ColdFusion

ColdFusion is a dynamic web application server and a Rapid Application Development (RAD) toolkit that runs on Java. This document gets you started on ColdFusion (2016 release). This document talks about various aspects of ColdFusion from installing to deploying an application on a server.

Installing ColdFusion

Download the 32-bit server or the 64-bit server, according to your system configuration. You can download a trial version from the download site.

While installing, you can see two installation options:

  1. Installing server configuration: The ColdFusion server configuration contains an embedded copy of Tomcat. To install the server configuration, follow the procedure in Installing the server configuration.
  2. Installing JEE configuration: Deploy ColdFusion as a Java application on a standards-based Java Enterprise Edition application server. To install the JEE configuration, follow the procedure in Installing the JEE configuration.

In addition, refer to the ColdFusion support matrix for server and OS-based configurations.

If you are migrating from an older version of ColdFusion to ColdFusion (2016 release), refer to the migration guide.

Starting the ColdFusion Administrator

After installing ColdFusion, log in to the ColdFusion administrator to verify a successful installation.

The ColdFusion Administrator is a centralized interface for configuring your ColdFusion server. You can configure settings for mail, database connections, debugging options, security, and so on.

The default location of the ColdFusion Administrator login page is http://servername:8500/CFIDE/administrator/index.cfm, where servername is the fully qualified domain name of your host machine. Common values for servername are localhost or (each refers to the web server on the local computer).

The default port number for the server configuration is 8500. If the port is occupied, then the next available port number is taken.

For more information, refer to Configuring and Administering ColdFusion.

ColdFusion Builder

ColdFusion Builder is an IDE for CFML-based projects or applications using ColdFusion Enterprise or Standard server. Since ColdFusion Builder is based on Eclipse, it works easily with other Eclipse plugins.

Like any IDE, ColdFusion Builder is equipped with a code editor, a compiler, a debugger, and code assist.

To know more about ColdFusion Builder, refer to Getting started with ColdFusion Builder.

ColdFusion basics


You can write ColdFusion Markup Language (CFML) in two ways- tag-based and script-based. For example:

Tag-based Script-based

<cfoutput>Hello World!</cfoutput>

         greeting="Hello World!";



ColdFusion is a weakly typed language. The same variable can act as multiple data types. For example,


The variable x can act like a numeric type, as shown below:


The variable x can also act like a string type, as shown below:


In ColdFusion, there are two classes of variables by type:

  1. Simple: Simple variables include String, Numeric, Boolean, or DateTime.
  2. Complex: Complex variables include Structs, Arrrays, Queries, or Images.


In ColdFusion, a string is a quote ( ' or " ) followed by zero or more letters, numbers, or symbols, and followed by another quote ( ' or " ). For example,


myString1="Welcome to ColdFusion.";


There are string functions in CFML for string manipulation and display. To see a list of all string functions, refer to String functions.

For example, use the len function as follows:

       myString="That's one small step for man, one giant leap for mankind.";

The output is 58, which is the length of the input string including spaces.


In ColdFusion, you can create arrays explicitly, by using a function to declare the array and then assigning it data, or implicitly by using an assignment statement. You can create simple or complex, multidimensional arrays.

You can declare arrays of strings, numbers, or objects. For example,



To create an array, first create an array object using the ArrayNew function. For example,


   myArray = [];



The example creates an array object for a one-dimensional array and then populates the array with the Fibonacci series.

For a complete list of array functions in CFML, see Array functions.


A list in ColdFusion is a string with delimiters. A delimiter separates each item in the list. For example,


To find the last element in a string, use the ListLast function, as shown below:



       WriteOutput(ListLast(myList)); //Outputs the last element in the list, Shanghai


For all list functions in ColdFusion, see List functions.

Using member function, you can re-write the example above as shown below:



        WriteOutput(myList.listLast()); //Outputs the last element in the list, Shanghai


For a list of member functions in ColdFusion, see Member functions.


A struct is a data structure that stores key-value pairs. It is similar to a HashMap in Java.

Create a struct object to hold the data. For example,


To populate the struct with data, type myStruct.key1="value1";

For example,


       myStruct.key1="John"; // Using dot notation
       myStruct["key2"]="Paul"; // Using associative array notation
       WriteOutput(myStruct.key1 & "<br/>"); // John
       WriteOutput(myStruct.key2); // Paul


Using literal syntax,


       myStructLiteral={key1="one",key2="two"}; // Using literal syntax
       WriteOutput(mystructLiteral.key1 & "<br/>"); // one
       WriteOutput(mystructLiteral.key2); // two


Loops in ColdFusion

You can iterate over a set of data and return values based on a condition. For example,

for (initialization;condition;iteration){

     // statements


For example,


     for (i=1;i <=10; i++) {


Pre-condition loops

Pre-condition loops evaluate a condition at the beginning of a statement, and continues to loop till the condition is true.

while (condition) {

     // statements


For example,

       x = 0;
       while (x < 10) {
             WriteOutput(x & " "); // 1 2 3 4 5 6 7 8 9 10

Post-condition loops

In this type of loop, the statements enclosed inside the do {} will execute irrespective of the condition.

do {

     // statements

} while (condition);

For example,

       x = 0;
       do {
               WriteOutput(x & " "); // 1 2 3 4 5 6 7 8 9 10
             } while (x < 10); 

Array loops

You can iterate over each element in an array. For example,

for (element in [1,2,3,4,5]){

    WriteOutput(element); // Outputs 12345


Struct loops

You can iterate over each struct member and apply struct operations. For example,


for (key in myStruct){

     WriteOutput(#key# & ":" & #myStruct[key]#); // Outputs a:1 b:2…


List loops

You can iterate over each element in a list. For example,


for (element in myList){

     WriteOutput(element); // Outputs abcde


Data handling in ColdFusion

Handling record sets in databases is a key component of ColdFusion. ColdFusion has built in support for many databases including MS SQL, MySQL, Oracle, Derby, and Postgres.

You can use <cfquery> and call a SQL statement using a datasource. A datasource is the collection of settings you can use to communicate with a database, such as, database type, sever, port, tablespace, or database, username and password.

For example,

<cfquery name="myQuery" datasource="cfdocexamples">
<cfdump var="#myQuery#" >

You can also use QueryExecute within cfscript to query a table. For example,


     myResult=QueryExecute("SELECT FIRSTNAME,LASTNAME FROM EMPLOYEES WHERE DEPARTMENT='Sales' AND LOCATION in (?,?)",["Newton","San Francisco"],




For a list of all query functions, see Query functions.

Query loops

You can iterate through the contents of a recordset and display the contents. For example,


     myQuery = queryNew("id,value", "integer,varchar",[

    [1, "East"],

    [2, "West"],

    [3, "North"],



 for (row in myQuery){
 WriteOutput(row.id & ":" & row.value);  // Outputs 1:East;2:West;3:North;4:South;




Application cfc is used to define settings that are common to an application.  Application.cfc defines application level variables and event handlers (functions invoked at various application lifecycle events).

There are various lifecycle events in your ColdFusion applications. To know more about the events, refer to the Application.cfc reference.

For example,

component {

    this.name = "AppName";

    this.datasource = "AppDataSource";

    this.sessionManagement = true;


ColdFusion ORM

ColdFusion Object Relational Mapping (ORM) lets you access and manipulate databases using CFCs. ORM is built on Hibernate. Using ORM, you can build object oriented applications. You can concentrate on building the business layer without worrying about CRUD operations to the database. ORM generates SQL statements and defines the CRUD methods for you.

Update the Application.cfc as follows:






There is a list of ORM-related configuration for your CFC. Find it here.

Next, map an object to a database and define the persistence, as shown below:

component persistent="true"{

     property name="artistid" generator="increment";

     property firstname;

     property lastname;


Create a ColdFusion page to list all artists with first and last names, as shown below:





For more details, see ORM in ColdFusion.

Object-oriented concepts in ColdFusion

Object-oriented programming in ColdFusion relies heavily on ColdFusion Components (CFCs). A component encapsulates data and the methods that can manipulate that data. Its parallel in java is the Java “Class”.

A CFC consists of:

  • Data/variables containing data.
  • Methods to manipulate that data.

Using a CFC, you can:

  • Share properties and variables between methods
  • Share properties between methods defined in other CFCs
  • Inherit methods and properties

Create a CFC (greetingsobjectFile.cfc) that displays the string "Hello World!":

component greetings {
       function helloWorld(){
             var myGreeting="Hello World!";
             return myGreeting;

Create an object greet that calls the helloWorld method and displays the appropriate result.

<cfset greet=new greetings()>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy