Skip to main content
January 18, 2007
Answered

Problem with UTF-8 encoding

  • January 18, 2007
  • 23 replies
  • 3250 views
The problem is that although I have finally gotten the static text to display right the dynamitic which is queried from a mySQL database is not being displayed correctly,

I have set checked the database the Spanish, French, and other translations for the contents are there with the correct lettering. I have updated the mySQL drivers to 5.0 as recommended by Adobe, I have placed in the URL string of the JDBC the ?useUnicode=true&characterEncoding=UTF-8 as suggested by another forum. I have even checked all the pages properties to make sure that they are in UTF-8 encoding format, below is a sample of the code I am using what is wrong with the code, or what do I need to change to fix this problem. You may check the site at www.scoringag.com and try the languages translations to see further examples of the problem.

We are using MX7 MySQL4.1 Jconnect5.0

Sample code below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>

<!---
**
* CF MX Admin "Application.cfm" file
* This file establishes the cfadmin application, as well as creates handles
* to the services using the factory via CFOBJECT.
*
* Copyright (c) 2001 Macromedia. All Rights Reserved.
* DO NOT REDISTRIBUTE THIS SOFTWARE IN ANY WAY WITHOUT THE EXPRESSED
* WRITTEN PERMISSION OF MACROMEDIA.
--->

<!--- Set multi-language utf-8 values here
---------------------------------------------------------------------->
<cfprocessingdirective pageencoding="utf-8">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<cfset URLenChar = "utf-8" >

<!--- Set encoding to utf-8. --->
<cfset setEncoding("URL", "utf-8")>
<cfset setEncoding("Form", "utf-8")>

<cfparam name="url.login" default="">

<!--- Set the output encoding to utf-8 --->
<cfcontent type="text/html; charset=utf-8">

</head>

<cfset SESSION.locale='es'>

<!--- <div id="home_contents"> --->
<style type="text/css">
<!--
.style2 {color: #ff0000}
-->
</style>

<div id="content">
<table align="center" width="100%">

<tr><center>

<div align="center" style="width:100%; font-size:13px; font-weight:500; color:#000000; "><br />
<a href=" http://www.cfsan.fda.gov/~dms/fsbtac23.html" target="_blank" class="style2" >*** Important Information (please read)! ***<br />
FDA Fact Sheet ScoringAg has the Solution! </a><br />
<a href="Public/docs/Acciones de la FDA en la nueva legislacion del Bioterrorismo.pdf" target="_blank" class="style2">Haga clic para aquí ver
los Hechos de los USA FDA - en Español</a> <br />
<br />
<cfscript>ssite.translate('#SESSION.Locale#', 1, 111);</cfscript></div><br />

This topic has been closed for replies.
Correct answer
And while you two are debating the issue I removed the Dateformat tag in the copyright clause at the bottom of the page, problem fixed. Don't ask why, I don't know but it works now, go figure, now I move to my next problem, real time video feed of a cow walking, don't ask I just do, just do :)

David Gamache

23 replies

Inspiring
January 18, 2007
I did not review all the previous suggestions, so parden me if this has
allready been tried and failed. But then I set the encoding on pages I
do so as follows.


<cfprocessingdirective pageencoding="UTF-8">

<cfscript>// note: only needed if you are submitting and/or receiving
form values, but does not hurt to always have available.
SetEncoding("form", "utf-8");
SetEncoding("url", "utf-8");
</cfscript>

<!--- Note the reset parameter in the cfcontent tag, this clears
anything that has already been generated for this response. I put it on
the same line as the doctype so there are no extra white space and lines
that can throw off some IE browsers versions. --->

<cfcontent type="text/html; charset=UTF-8" reset="yes"><!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>
</head>

<body>
January 18, 2007
One of the first things I did was use the following code to see if a simple page could display the translations and you see the results below, I am at my wits end here, folks someone out there surly knows what is wrong and can tell me how to fix it.

David Gamache
<cfprocessingdirective pageencoding="UTF-8">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<cfcontent type="text/html; charset=UTF-8">
<cfscript>
SetEncoding("form", "utf-8");
SetEncoding("url", "utf-8");
</cfscript>
<title>Untitled Document</title>
</head>

<body>
<cfquery name="translations2" datasource="#request.tracebackDSN#">
SELECT *
FROM translations
WHERE 0 = 0
AND translation_id = '1111'
AND page_id = '1'
</cfquery>
<cfoutput query="translations2">#translations2.es#
<br />
HELLO<br />
#SESSION.locale#
</cfoutput>
</body>
</html>

Establezca y Mantenga que sus Registros en ScoringAg f�cil y econ�mico Protegen la Provisi�
HELLO
es
Inspiring
January 18, 2007
> Invalid CFML construct found on line 3 at column 1.
>
> is the error you get when you place the cfprocessingdirective tag before the
> cfcompoment tag, but hey at this point maybe beating my head on the wall will
> work

You only need <cfprocessingdirective> if the FILE ITSELF has UTF-8
characters in it. You DO NOT need it if it's simply processing UTF-8 data.

I think you need to go back to basics, and do a bit of unit testing. Write
a CF template that simply has a <cfquery> which pulls some of your data
back from the DB, and outputs it on the screen. Does that work?

(remember to have the <meta> tag and the <cfcontent> tag too).

--
Adam
January 18, 2007
Invalid CFML construct found on line 3 at column 1.

is the error you get when you place the cfprocessingdirective tag before the cfcompoment tag, but hey at this point maybe beating my head on the wall will work

David Gamache
January 18, 2007
Sabaidee I have been googling, reading and looking at docs for two days now, this one has me stumped, it does not make any sence, but that is what I live for, anytime you find these problems and got to go beat your head on a wall :)

Inspiring
January 18, 2007
hmm.... makes me wonder if it has anything to do with the text from db being returned through a cfc... i am not sure what default encoding/character set is used by CF in that case and how to change it.
does PaulH know, being an Adobe Community Expert? i am trying to find it in the docs and google for it now...

i would start by moving the <cfprocessingdirective...> line to the top of the cfc, before the <cfcompoment> tag....

i would also try another "stupid" thing and change <cfset setEncoding(...> for both form and url scopes in your Application.cfm to:
<cfscript>
setEncoding("form", "utf-8");
setEncoding("url", "utf-8");
</cfscript>

and remove them from other pages.
January 18, 2007
ok that did not work, as for the I have added the characterSetResults = UTF-8 and the collation and character encoding is UTF8_unicode_ci for all languages that we have translations for.
Inspiring
January 18, 2007
dagamache wrote:
> of the JDBC the ?useUnicode=true&characterEncoding=UTF-8 as suggested by
> another forum. I have even checked all the pages properties to make sure that
> they are in UTF-8 encoding format, below is a sample of the code I am using

and is your mySQL database's encoding actually utf-8?

also viewing data via the db's tools are often misleading when it comes to
encoding, what looks ok in the tool might end up as mojibake or garbage when
passed thru a JDBC driver.

January 18, 2007
I have checked both the database from the admin tools and from looking into it directly and everything looks fine in the tools just the JDBC returns are messed up

David Gamache
January 18, 2007
I am waiting for the Server company to reboot the Coldfusion server to see if the &characterSetResults=UTF-8 works and I have looked into the database and everything looks correct but then I don't know Spanish or German so I am not sure, I should know more in about 20 minutes.
Inspiring
January 18, 2007
you don't have to tell me about trying something stupid to get it right: so many of those things i have tried in order to make my Lao language site work...

anyway, the translate function does not seem to have anything to do with it, so back to the other checks:
- did you try adding &characterSetResults=UTF-8 to the JDBC url?
- did you check that the data stored in the db is actually correct? (use something like phpMyAdmin or similar to access the db and browse the tables to see the contents of the fields)

also, check what are the collation and character encoding settings in your db.

is the Spanish text displayed the same on your development machine or is it displayed correctly? in my case with Lao language everything worked fine on my comp, but on the server it all got screwed up, and the problem was solved by upgrading the server's CF MySql drivers to the latest version. oh, i see you are using connector/J 5.0... so should not be a problem... not sure about MySql 4... i am using 5...

try the above 2 suggestions and let me know if they helped.