luceecoldfusion-2016fw1

fw/1 - Can not display foreign characters in views


I have got the following main Controller default action in fw/1 (framework one 4.2), where i define some rc scope variables to be displayed in views/main/default.cfm.

main.cfc

 function default( struct rc ) {

        rc.name="ΡΨΩΓΔ";
        rc.dupl_name="üößä";
    } 

views/main/default.cfm

       <cfoutput>
    <p> #rc.name# </p>
    <p> #rc.dupl_name# </p>
      </cfoutput>

and finally in layouts/default.cfm

<cfoutput><!DOCTYPE html>
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>
            A Simple FW/1 Layout Template
        </title>
    </head>
    <body>
       #body# 
    </body>
    </html>
</cfoutput>

Unfortunately i receive the following output

ΡΨΩΓΔ

üößä

Any idea that could help me?

Regards


Solution

  • Because I already gave you a solution within my comments, I’m posting it as an answer here, so that others with similar issues may find the root of their charset issues.

    The issue described above is very often the result of conflicting charset encodings. For example, if you are reading an ISO-8859-1 encoded file and outputting it with UTF8 without having them converted (de-/encoded) properly.

    For the purpose of sending characters through a webapp as you are doing, the most common charset encoding as of today is UTF-8.

    All you need to do is to harmonize characterset encodings or at least ensure that the encodings are set in such a manner that the processing engine is able to encode and decode the charsets correctly. What you can do in your case is:

    1. Verify the encoding of the template .cfm file and make sure it’s saved as UTF-8
    2. Define UTF-8 as your web charset in Lucee Administrator » Settings » Charset » Web charset
    3. Define UTF-8 as your ressource charset in Lucee Administrator » Settings » Charset » Resource charset.
    4. Make sure there are no other places where charset encodings are incorrectly set, such as a http server response header of “content-type: text/html;charset...” or a html meta-tag with a charset directive.
    5. If you have other type of ressources, such as a database, then you may need to check those also (connection and database/table settings).

    Note: That charset doesn’t always have to be UTF-8 (UTF-8 might use multiple bytes for certain characters). There may be use cases you would achieve the same result with single byte encodings, such as ISO-8559-1, that would also need less computing ressources and less payload.

    I hope this may help others with similar issues.