Skip to main content
Inspiring
November 29, 2011
Answered

ColdFusion won't display unicode (utf-8) characters

  • November 29, 2011
  • 2 replies
  • 18830 views

I have a very basic page with some unicode characters in it. ColdFusion won't properly display them. If I resave the page as .html (so the coldfusion server doesn't process it), the characters display fine.

Below is my page. Notice that the charset is set to utf-8.

I'm using Dreamweaver CS5.5. Running IIS 7 and CF 9.

The text "why isn’t this working" has a smart apostrophe that DOES NOT DISPLAY PROPERLY when run through CF. I've searched around and all I see is that CF has unicode "turned on by default" but no where can I find where to make sure it is set.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

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

<title>Untitled Document</title>

</head>

<body>

why isn’t this working?

</body>

</html>

This topic has been closed for replies.
Correct answer 12Robots

>>  I've already set the charset in the <head> of my document, why do I need to set it again?

To be clear, these are two different things.  Set the encoding in the <head> of your document is for the web browser to know how to render the content. Setting the processing directive is to tell CF how to compile the file. They are very different things for different purposes and, for whatever reason, may not always match.

You could try changing the default that Java uses. Try adding this to your Java settings in the ColdFusion admin:

-Dfile.encoding=UTF8

Jason

2 replies

Participating Frequently
November 30, 2011

Hello,

I encountered this problem previously during my web application development efforts, and discovered a workaround, my CFM files were ANSI and I needed to have them display UTF-8 characters that were static content in the CFM files.

The workaround I used was to open the CFM files with notepad, and then resave them as UTF-8 files with the same code. Notepad gives the option to save a file in ANSI format or in UTF-8 format. After I did this with my web application CFM files they then correctly showed the UTF-8 characters.

Probably not the best solution, but at least it works. Would probably work the same for ASP.NET and PHP files, as well as for COLDFUSION files. Hope this helps.

Michael G. Workman

mworkman@usbid.com

http://www.usbid.com

http://ic.locate-ic.com

jeremy1Author
Inspiring
November 30, 2011

Hi Michael,

I believe what Notepad is doing is just adding the BOM to the file when you save it as "UTF-8". Dreamweaver can do this for you by going to Modify > Page Properties, then clicking Title/Encoding and checking on Include Unicode Signature (BOM). This will work to make CF properly display unicode characters.

The reason this does not seem to be a proper solution to me is that:

1) Developing in a team environment it is pretty tough to enforce that everyone has this checked on. Maybe there is an easy way to tell other than opening every file and going into tthat one dialog in Dreamweaver.

2) PHP and HTML files do not need this BOM in order to display unicode characters. I've already set the charset in the <head> of my document, why do I need to set it again?

Ideally there would be a universal setting in CF to just make it act like HTML, PHP, et al and pay attention to the charset instead of garbling my text. Also CF claims to default to unicode anyway....but this doesn't seem to be the case!! For some reason I now have to add a <cfprocessingdirective> tag to every page in my app that may display text to the user. Seems like a pain and extra work to me!

How come no one else seems to be having this problem?

12Robots
12RobotsCorrect answer
Participating Frequently
November 30, 2011

>>  I've already set the charset in the <head> of my document, why do I need to set it again?

To be clear, these are two different things.  Set the encoding in the <head> of your document is for the web browser to know how to render the content. Setting the processing directive is to tell CF how to compile the file. They are very different things for different purposes and, for whatever reason, may not always match.

You could try changing the default that Java uses. Try adding this to your Java settings in the ColdFusion admin:

-Dfile.encoding=UTF8

Jason

12Robots
Participating Frequently
November 29, 2011

Try adding this to the top of the page:

<cfprocessingdirective pageencoding = "utf-8">

jeremy1Author
Inspiring
November 29, 2011

Ok, that did work...but do I really need to add that tag to EVERY single page in my entire application? Surely CF wouldn't be so terribly clunky.

I also found that by turning on the BOM in dreamweaver it started to display unicode properly.The problem with turning on the BOM for us is that we develop in a team and it would be very easy for someone to forget to turn this one little setting on as it's NOT the dreamweaver default.

I need a global default. Am I the only one in the world using codlfusion and utf-8? It seems rediculous that CF would make you put that tag in every page, especially when it claims to have UTF-8 as the default anyway.

Any other solutions?

12Robots
Participating Frequently
November 29, 2011

You could try adding it to your App.cfc, perhaps in onRequest or onRequestStart. I have not tested it, so I don't know if that would work, but I don't know why it wouldn't.