Accessibility
 
Home > Products > ColdFusion > Support > Internationalization
ColdFusion Icon Macromedia ColdFusion Support Center - Internationalization
Character encoding

Character encoding specifies mappings from a character set to the integer numbers that represent the characters on a computer.

To read a CFM page, process information, and decode Form and URL variables, ColdFusion uses, by default, the character encoding specified by the Java default locale variable.

For example, if the ColdFusion MX server computer's Java default locale is set to French(Standard), ColdFusion uses the character encoding for that locale, ISO-8859-1, to read pages and process information. It uses the UTF-8 character encoding for output.

For each of these operations, you can override the character encoding default for a page, as the following sections explain.

 
Reading a ColdFusion page with a nondefault character encoding
Macromedia recommends that you encode all international application pages as UTF-8 with a byte-order mark (BOM), so that ColdFusion automatically detects the page as UTF-8 encoded; no cfprocessingdirective tag is needed. The BOM sets the first byte of a UTF file, so the program reading the page recognizes which encoding is in use.

If this is not possible, to specify that ColdFusion reads a page with a character encoding other than the Java default locale value, you use the cfprocessingdirective tag and pageencoding attribute, as follows:

<cfprocessingdirective pageencoding=" encoding ">

Typically, you assign one of the following values to encoding :

EUC-JP (Japanese)
EUC-KR (Korean)
ISO-8859-1 (Western European and English)
SHIFT_JIS (Japanese)
UTF-8 (All Languages)

If you save application pages in the default character encoding for your language, ColdFusion automatically reads them correctly. (This article assumes that the production ColdFusion server has the same Java default locale value as the computer on which you develop the application.)

To cause the ColdFusion server to read a page in a different encoding, you use the cfprocessingdirective tag at the top of the page. For example, assume that the Java default locale is set to French. ColdFusion automatically reads and renders the page in French characters. To cause ColdFusion to read the page and render it in Japanese characters, you use the UTF-8 encoding. The following code shows an example.

You cannot propagate the effect of the cfprocessingdirective tag by putting it in an application.cfm page. You must add it to each page that has a nondefault encoding.

 
Generating ColdFusion page output with a nondefault character encoding
By default, ColdFusion MX uses the UTF-8 character encoding to render ColdFusion page output. With UTF-8 encoding, a browser receives page content as UTF-8 characters.

To specify another output character encoding for the HTTP output of a page, including Form and URL variables, cookies, and cfmail tag content, you can use the cfcontent tag, as explained in this section. The cfcontent tag does not affect internal output such as data for a database, a file, or a ColdFusion variable; its function is unrelated to the cfprocessingdirective tag.

The cfcontent tag syntax is as follows:

<cfcontent type="text/html; charset= encoding ">

You assign an encoding value to encoding .

If you put the cfcontent tag in an application.cfm file, its effects propagate throughout the application, overriding the ColdFusion default value.

 
Decoding HTTP Form and URL variables with a nondefault character encoding
By default, ColdFusion uses UTF-8 character encoding to decode and send Form and URL variables. By default, HTML does not process UTF-8 encoded data; its default is ISO-8859-1.

Because ASCII encoding is a subset of UTF-8, ColdFusion can process ASCII data automatically. To decode and send Form and URL variables in any other encoding (including the ColdFusion default character encoding), you must use the setEncoding function. Its syntax is as follows:

setEncoding("_variable-type_", " encoding ")

You assign an encoding value to encoding .

If you put a setEncoding function call in the application.cfm file, its effects propagate through the ColdFusion application. Alternatively, put a setEncoding function call in the action page of each form that requires it.

Set the encoding value as follows:

If the form page has a cfcontent tag, set the encoding to the same value as the tag.
If the form page does not have a cfcontent tag, set the encoding to UTF-8, regardless of the form page encoding.

For each type of Form or URL variable that might contain non-ASCII data, put one setEncoding function call in the application.cfm or form page.

To Table of Contents Back to Previous document Forward to next document