Adobe ColdFusion

From Bauman National Library
This page was last modified on 8 June 2016, at 21:05.
Adobe ColdFusion
Developer Adobe Systems Incorporated
First appeared 1995; 27 years ago (1995)
Stable release 2016.0.0.297996 / February 16, 2016; 6 years ago (2016-02-16)
Implementation language Java
OS Cross-platform
License Proprietary

ColdFusion - an interpreted programming language, created to generate HTML on the web server and working with databases. The language was created by brothers Jeremy and Joseph Allaire, but at the moment the product has Adobe. Starting with version 1.5, ColdFusion contained compatibility with C ++, allowing users to develop additions to the language. Years later, it served as the basis for creating ColdFusion Extension (CFX) Tags, the present method is to supplement the language. Application development using Cold Fusion requires no programming languages ​​such as Perl, C / C ++, Visual Basic or Delphi. Instead, you create an application by inserting the normal (standard) HTML file special tags to work with databases.


In 1995, two brothers, Jeremy and Joseph Allaire in the United States founded the new company «Allaire Corporation» to advance the world's first web application server, which they called DBML (DataBase Markup Language) and who later was renamed to CFML (ColdFusion Markup Language - «Markup Language ColdFusion»). One of the reasons for creating ColdFusion was precisely the complexity of creating sites, data-driven using CGI programs. In front of one of the brothers - Jeremy - task was to periodically update the electronic version published in hard copy magazine. Occupation it was extremely tedious, and Jeremy turned to his brother-programmer with a request to write to him any application that would have saved him from wasting time and energy, and allow him to concentrate on the main task - in fact, updating the electronic version of the magazine . When the project was completed, the two brothers realized that the baked hot cake that is sure will be enjoyed by many. The brothers founded the new company and, without further ado, gave it his name.Having invested in their offspring 18 thousand dollars of personal savings, six years later, in 2001, the brothers sold him of Macromedia more than $360 million. After the merger was released ColdFusion 5.0. In June 2002, Macromedia released Macromedia ColdFusion MX, the version called by analogy with the rest of its line of products. ColdFusion MX was completely rewritten and is based on the Java 2 Enterprise Edition (J2EE). In ColdFusion MX was also built good support for Macromedia Flash (by Macromedia Flash Remoting MX). April 18, 2005 the company began to acquire Macromedia Adobe Systems. December 5, 2005 the transaction was completed for $3.4 billion.


Adobe ColdFusion - is a kind of application server that mediates transforming your code written in high level language called CFML (ColdFusion Markup Language) tags in HTML-document that can display a Web browser, and then sends the result to the client application. In turn CFML - a programming language, often called the extension of HTML, as it is nothing more than a standard set of tags that can be inserted into the code of your web page. Sources language - simple text files that differ only with HTML extension - *.cfm.


User requests processing

  1. Web browser sends a request to a web server with the requirement to open a file ColdFusion. These files have the extension .cfm.
  2. After receiving the request, the web server forwards it to the application server ColdFusion.
  3. The application server parses the template and perform the actions to meet the prescribed tags and functions CFML, interacting, if necessary, with other services and applications, such as data sources or mail server. As a result of the dynamic created by the resulting HTML page.
  4. The server application brings together newly created dynamic part of the page with the static part of the original template, and returns the resulting page of the web server.
  5. Web server sends the resulting page of the ColdFusion server to send a request to the client machine.

Data Types

With ColdFusion, the following basic data types:

  • Integer - integer;
  • Floating - Real;
  • Character - string;
  • Boolean - Boolean;
  • Date - Date;
  • Time - Time.

In addition, in ColdFusion are several more complex types:

  • Lists - List;
  • Structure - Structure;
  • Arrays - Array;
  • Request - Query;
  • COM objects (Component Object Model) - somobject.


The variables in ColdFusion have a certain scope and purpose and on these grounds relate to a specific category. These categories reflect the prefix that can be added to the variable name:

  • Caller - Variable call source; designed for variables from the templates when you specify custom tags ColdFusion
  • Attributes - Variable attributes of custom tags
  • Client - Client variables
  • Session - Session variables
  • Application - Variable applications
  • Server - Server variables

Defining variables

In a ColdFusion variable definitions there are tags like <CFSET> and <CFPARAM> :

  • Tag <CFSET> One of the options to define a variable in ColdFusion is an indication of the tag <CFSET> . If the variable already exists, it is determined again. Syntax:
     <CFSET variable_name = expression>
    For example, to determine the FirstName variable with a value of "Anjuta" should be included in the current Web-page the following code:
     <CFSET FirstName = "Anjuta">
  • Tag <CFPARAM> Another option define a variable in ColdFusion is the use of the tag <CFPARAM> , which also provides the ability to specify the data type and default values ​​in including can be used to verify the existence of a variable. syntax:
     <CFPARAM NAME = "variable_name" TYPE = "data_type" DEFAULT = "default_value">
    There are two ways to use the tag <CFPARAM> , depending on the task: • The use of the tag <CFPARAM> only with the name of the attribute (NAME), checks for the existence of the variable; if the variable does not exist, ColdFusion Server stops processing the page; • Using the tag <CFPARAM> with the name attribute (NAME) and defaults (DEFAULT) to verify the existence of an optional variable; If the variable already exists, the processing code is continuing, and the value does not change; if the variable does not exist, creates a variable with the name specified by the NAME attribute and the value specified attribute DEFAULT. The following example shows how to use the tag <CFPARAM> to define a variable, if it is not:
     <CFPARAM NAME = "Form.Gender" DEFAULT = "male">
    We also options for an optional attribute TYPE:• any - any value; • array - any array; • binary - binary value; • boolean - Boolean value; • date - date and time; • numeric - a numeric value; • query - query object; • string - character value; • struct - structure; • UUID - Universal Unique Identifier ( Universally Unique Identifier) ​​in the format "XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXXXXX" where "X" - a hexadecimal digit that evaluates or 0-9 or A-F; • name - the name of an existing variable. For example, to define a variable of type Moneyness boolean:
     <CFPARAM NAME = "Moneyness" DEFAULT = True TYPE = "boolean">

Client, server, session and applications variables

Besides different ways declared the client, server, session variables, and applications:

  • Client variables can be used for purposes such as preservation of the parameters characterizing the font, color, style and page layout, as well as storage of the counter value and the recent visit to the page, the control of the results of surveys, tests, purchases in e-shops, and so on. With ColdFusion, there are three possible mechanisms for the storage of client variables: Registry (Registry) - in this case, the variables are stored in the registry of the operating system (system registry). This mechanism is variable storage is the default value. Cookie (cell) - the name speaks for itself, such a mechanism involves storing variables in cookies. Data Source (Data source) - in this case, the client variable storage is carried out in a user database through prescribed ODBC, OLE DB or native data source. During the selection mechanism for storing client variables responsible attribute CLIENTSTORAGE tag <CFAPPLICATION> . The following example uses the tag <CFPARAM> will create a client variable Client.NameCruise with the default value "Liberty":
     <CFPARAM NAME = "Client.NameCruise" DEFAULT = "Liberty">
  • Session variables are used for one-time fix a visit Web-page. The session is determined by an individual user, whereby each user has a separate session and the session specific set of variables. The session begins with the first entry on the Web-site and formally ends at the end of the browser. Thus, a single user can operate multiple sessions, pre-launch the browser as necessary. We're talking about the end of the formal session, then session is the period of time after which inactive when the user session ends, and therefore the life cycle of variable stops. That is, you are registered on one of the Web-sites for some time worked and not closing your favorite browser, gone away from your computer, for example, gone for lunch. And after a certain period of time the session is terminated. Come to dinner, trying to make any action in the open browser, but nothing happens. The fact is that session variables, some of which could be responsible for the access to the Web-site, ceased to exist. Session variables can be used for purposes such as storing user registration settings, storage computing based on information from client variables, temporary storage of the results of queries to the data, in general, the control of all the variables that require preservation only during a single session. For example, declare a session variable Login follows:
     <CFSET Session.Login = "true">
  • Variable applications associated with a single application and is available to all clients of the application. Application variables can be used for purposes such as keeping records of calls to the current application, storing the results of queries to the data, which can handle all the customers application, storage items of data sources, as well as storage of application title and standard messages, and so on. D.
    To use application variables need to create a configuration file named Application.cfm and add the definition of the application name using the NAME attribute of the tag <CFAPPLICATION> . These definitions in the configuration file apply to all adjacent to the file the application page. That is, downloading a particular page ColdFusion, the system looks for the file Application.cfm back to the root directory of the application and the first successful attempt to found the contents of the file is placed in the beginning of the loaded ColdFusion-page:
    For example, declare a variable application textFieidsize follows:
     <CFPARAM NAME = "Application.textFieldSize" DEFAULT = "25">
  • Server variables are not tied to any application or client, and directly related to the ColdFusion Server, and for this reason, you can access them all from different clients or applications on the server. These variables are stored in the server memory as long as he will not be suspended. For example, declare a variable CountuserActive server using the tag <CFSET>:
     <CFSET Server.CountuserActive = 0>
    To delete and view server variables is carried out by analogy with the session variables and variable applications. For example, removal of the server variable CountuserActive can be done in the following way:
     <CFLOCK TIMEOUT = "30" SCOPE = "Server" TYPE = "Exclusive">  <CFSET StructDelete ( Server, "CountuserActive")> </CFLOCK>

Working with Data

ColdFusion allows you to work with these drivers through ODBC, OLE DB, and use their own drivers for Oracle, Sybase, Informix, DB2. With ColdFusion there is a tag <CFQUERY> , allowing you to transfer SQL-query the database for performing a specific action, and to retrieve the resulting data. This is not the only tag in ColdFusion, it is designed to work with databases, but it can be defined as the primary and requires special attention. Syntax:

NAME = "query_name" 					query name.
DATASOURCE = "ds_riame" 				data source to which the inquiry is addressed.
DBTYPE = "type" 						Type of database driver. Optional.
OBSERVER = "dbms" 					The name of the database server. Optional.
DBNAME = "database name" 			DB Name (only for Sybase System 11 and SQLOLEDB). Optional.
CONNECTSTRING = "connection string"	connection string to send to the ODBC-server.
USERNAME = "username" 				username. Optional.
PASSWORD = "password" 				user password. Optional.
MAXROWS = "number" 					Specifies the maximum number of entries for the returned result. Optional.
BLOCKFACTOR = "blocksize" 			The maximum number of entries for simultaneous sampling (fetch) from the server. Optional.
TIMEOUT = "milliseconds" 			Maximum waiting time of the query in milliseconds. Optional.
CACHEDAFTER = "date" 				date value. Optional. Allows the use of caching query, if the date of the original request takes the value of a later date established by a CACHEDAFTER.
CACHEDWITHIN = "timespan" 			interval, use the ColdFusion CreateTimeSpan. Optional. It allows you to use query caching, if the date of the original request falls into the period of time that is determined by the function CreateTimeSpan.
PROVIDER = "COMProvider" 			COM provider. Optional. Only for OLEDB.
PROVIDERDSN = "datasource" 			The name of the data provider. Optional. Only for OLEDB.
DEBUG = "Yes | No"> 					is used for debugging the query. Optional.
SQL-offers 							regular SQL command.

Arrays, structures and lists


Arrays (arrays) ColdFusion differ from traditional arrays, they are dynamic, and if their usual array size is constant, then arrays ColdFusion can change size depending on the addition or deletion of data. To use the array must be pre-declare it:
<CFSET MyNewArray = ArrayNew (x)>
where x - a number reflecting the dimension of the array, which can take a value between 1 to 3 (the most three-dimensional).

For example, create a one-dimensional array and write to an existing array of two elements are as follows:

<CFSET CruiseArray = ArrayNew (1)>
<CFSET CruiseArray [1] = "Museum of Jewish Horitage">
<CFSET CruiseArray [2] = "Ellis Island">

Check Array:

  • The ArrayisEmpty (array)checks if the array is empty.
  • The ArrayLen (array)returns the length of the specified array.
  • The isArray (value [, number])returns True, if the value is an array. Here the number - the number of enabling verification of compliance to specify the number of array elements.

Adding items:

  • The ArrayAppend (array, value)adds an element to the end of a given array.
  • The Arrayprepend (array, value)adds an element to the beginning of a given array.
  • The ArraylnsertAt (array, position, value)inserts the array element at that position.
  • The ArraySet (array, start_pos, end_pos, value)assigns a certain number of elements of the value of a one-dimensional array in the specified range.


To use the structure, you must first declare it:

<CFSET MyNewStruct = StructNew ()>

For example, create a structure and assign a value to its two components:

<CFSET TravelerStruct = StructNew ()>
<CFSET TravelerStruct ["RS1"] = "Nomar Garciaparra">
<CFSET TravelerStruct ["RS2"] = "Pedro Martinez">


Lists (lists) - a special type of character, made up of elements, separated by comma. You can define your own delimiter list. Moreover, the separator can consist of several characters. By default, the separator (delimiter) adopted a comma (,). Structure list - flat, so lists can not be nested within each other. Also, lists can not contain any "empty" elements. However, the list may be empty. This is equivalent to an empty value "". Creating a list:

<CFSET MyList = "Black, Magenta, Cyan, Orange, Darkgray, Pink, Gray, White, Lightgray, Yellow">

Search, sorting, checking and viewing lists

  • The ListFind (list, value [, delimiters])searches for values ​​in the list with the specified delimiter.
  • The ListFindNoCase (list, value [, delimiters])searches for value in the list of case-insensitive.
  • The ListContains (list, substring [, delimiters])returns to the position from which meets a given piece of text (substring).
  • The ListContainsNoCase (list, substring [, delimiters])returns to the position from which meets a given piece of text, insensitive.
  • The ListSort (list, sort_type [, sort_order] [, delimiter])sorts the items in the list based on a delimiter.

Creating a custom tag

A custom tag is a code with the possibility of multiple use and whose behavior may depend on the transmitted attributes. Using custom tag to speed up the process of developing Web-based applications and facilitate the maintenance of the future product. Custom tags in ColdFusion can be of two types:

  • Tags whose names contain the prefix CF_, - it tags developed directly using CFML language and is a file with the extension cfm;
  • Tags whose names begin with the prefix CFX_, developed in Java or C ++.

Create CF-tag

As already noted, CF-tags are CFML-based pages, and their names are written with the prefix CF_. For example, to call the tag placed on the page MyFirstTag.cfm, use the following structure:


When you call the tag can also transmit the values ​​of variables as attributes:

<CF_MyFirstTag Value = "Number">

Sample Code

The simplest example code

Consider the example of creating pages using CFML:

<! --- Set the variable FirstName --->
<CFSET FirstName = "Anjuta">
<! --- Display --->
Dear #FirstName, thank you for your interest in CFML.

Here we create a variable called FirstName and set the value to "Anjuta" and displays the contents of the tag <CFOUTPUT>, in this case, the text "Dear", then put a value variable FirstName and then the phrase ", thank you for your interest in CFML."

Querying the database

Create a database query that will open the session by booking on existing cruises. Suppose that during the registration e-mail at the same time is an input user name (Login ID). In this case, you want to create an interactive form to enter your email address and password for future potential traveler check the registration of the buyer. Then the query would look like this:

<CFQUERY NAME = "VerificatioriTra" DATASOURCE = "Traveler.db">
SELECT key_traveler, FirstName_traveler, LastName_traveler, EMail_traveler, Gender_traveler
FROM Traveler WHERE EMail_traveler = '#Form.EMail#'
AND Password_traveler = '#Form.Password#'

where Form.EMailand Form.Password – form variables, pre-filled by the user.

Using custom tags

Create custom tag on transformation temperature of the values ​​Centigrade (C) degrees Fahrenheit (F) and vice versa. Pre for this example, we define a new tag syntax:

    Value = "Number" [CtoF = "Boolean"]>

where Value- a numeric value required for conversion; CtoF- a Boolean value that indicates whether the conversion. And the attribute Valueis optional, unlike the attribute CtoF. Default direction conversion occurs in (C) (F), however, as well as by specifying the attribute to be 1, Yes, True or just at the mention of this attribute without a value. Now that the problem is defined and set forth the conditions, you can write a page TemperatureTransform.cfm

<! --- The temperature change --->
<CFIF isDefined ("Attributes.Value")>
    <CFIF isDefined ("Attributes.CtoF")>
        <CFIF isNumeric (Attributes.Value) AND isBoolean (Attributes.CtoF)>
            <CFIF YesNoFormat (Attributes.CtoF) equal "Yes">
                <CFSET Caller.Temperature = Attributes.Value *1.8 + 32 &amp; "F">
                <CFSET Caller.Temperature = (Attributes.Value-32) *5/9 &amp; "C">
            <CFSET Caller.Temperature = "Error1">
        <CFSET Caller.Temperature = Attributes.Value *1.8 + 32 &amp; "F">
    <CFSET Caller.Temperature = "Error2">

Then just have to use a new tag. For example:

<CF_TemperatureTransform Value = "21">
<CFOUTPUT>Temperature: iVariables.Temperaturel</CFOUTPUT>

The result will display the following line:

Temperature: 69.8 F

If there is need for conversion in the opposite direction, you can use our tag as follows:

<CF_TemperatureTransform Value = "69.8" CtoF = "No">
<CFOUTPUT>Temperature: # Variables.Temperaturel</CFOUTPUT>

That will allow to obtain the following result:

Temperature: 21 C

In the above example it was used variables attributes of custom tags Attributes, allow you to analyze the transmitted attributes in the body of a custom tag, and also used variable sources call Callerto pass variables from templates custom tags ColdFusion .

The use of language

Despite its many advantages and features, ColdFusion proper distribution has not yet been received. It continues to be used by experienced developers with experience, newcomers try to do without it, and it is certainly possible. Frankly ColdFusion - technology development, which is still unable to confront its competitors.


Project website: The language manual: