User Guide

Table Of Contents
418 Chapter 17: Developing Globalized Applications
You can also use the SetEncoding function to specify the character encoding of URL parameters.
The
SetEncoding function takes two parameters: the first specifies a variable scope and the
second specifies the character encoding used by the scope. Since ColdFusion writes URL
parameters to the URL scope, you specify "URL" as the scope parameter to the function.
For example, if the URL parameters were passed using Shift-JIS, you could access them as follows:
<cfscript>
setEncoding("URL", "Shift_JIS");
writeoutput(URL.name);
writeoutput(URL.ID);
</cfscript>
Note: To specify the Shift-JIS character encoding, use the Shift_JIS attribute, with an underscore (_),
not a hyphen (-).
Handling form data
The HTML
form tag and the ColdFusion cfform tag let users enter text on a page, then submit
that text to the server. The form tags are designed to work only with single-byte character data.
Since ColdFusion uses two bytes per character when it stores strings, ColdFusion converts each
byte of the form input into a two-byte representation.
However, if a user enters double-byte text into the form, the form interprets each byte as a single
character, rather than recognize that each character is two bytes. This will corrupt the input text,
as the following example shows:
1.
A customer enters three double-byte characters in a form, represented by six bytes.
2.
The form returns the six bytes to ColdFusion as six characters. ColdFusion converts them to a
representation using two bytes per input byte for a total of twelve bytes.
3.
Outputting these characters results in corrupt information displayed to the user.
To work around this issue, use the
SetEncoding function to specify the character encoding of
input form text. The
SetEncoding function takes two parameters: the first specifies the variable
scope and the second specifies the character encoding used by the scope. Since ColdFusion writes
form parameters to the Form scope, you specify "Form" as the scope parameter to the function. If
the input text is double-byte, ColdFusion preserves the two-byte representation of the text.
The following example specifies that the form data contains Korean characters:
<cfscript>
setEncoding("FORM", "EUC-KR");
</cfscript>
<h1> Form Test Result </h1>
<strong>Form Values :</strong>
<cfset text = "String = #form.input1# , Length = #len(Trim(form.input1))#">
<cfoutput>#text#</cfoutput>