Handling data in ColdFusion MX
385
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>
File data
You use the
cffile
tag to write to and read from text files. By default, the
cffile
tag assumes
that the text that you are reading, writing, copying, moving, or appending is in the JVM default
file character encoding, which is typically the system default character encoding. For
cffile
action="Read"
, ColdFusion MX 6.1 also checks for a byte order mark (BOM) at the start of the
file; if there is one, it uses the character encoding that the BOM specifies.
Note:
To specify the JVM default file character encoding, use the
-Dfile.encoding=
switch in the
JVM Arguments field of the ColdFusion MX Administrator Java and JVM Settings page.
Problems can arise if the file character encoding does not correspond to JVM character encoding,
particularly if the number of bytes used for characters in one encoding does not match the
number of bytes used for characters in the other encoding.
For example, assume that the JVM default file character encoding is ISO 8859-1, which uses a
single byte for each character, and the file uses Shift-JIS, which uses a two-byte representation for
many characters. When reading the file, the
cffile
tag treats each byte as an ISO 8859-1
character, and converts it into its corresponding two-byte Unicode representation. Because the
characters are in Shift-JIS, the conversion corrupts the data, converting each two-byte Shift-JIS
character into two Unicode characters.
To enable the
cffile
tag to correctly read and write text that is not encoded in the JVM default
character encoding, you can pass the
charset
attribute to it. Specify as a value the character
encoding of the data to read or write, as the following example shows:
<cffile action="read"
charset="EUC-KR"
file = "c:\web\message.txt"
variable = "Message" >
Databases
ColdFusion applications access databases using drivers for each of the supported database types.
The conversion of client native language data types to SQL data types is transparent and is done
by the driver managers, database client, or server. For example, the character data (SQL CHAR,
VARCHAR) you use with JDBC API is represented using Unicode-encoded strings.
Summary of Contents for ColdFusion MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......