Announcement Announcement Module
Collapse
No announcement yet.
Tomcat UTF-8 encoding problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tomcat UTF-8 encoding problem

    Hi all,

    I'm developing bilingual Arabic+English webapp with Tomcat 5.5, Spring 1.2 MVC+JDBC, and Mysql 5. Eclipse as IDE. http://forum.springframework.org/sho...omcat+encoding

    I've been facing problems with i18n of pages (fmt:message jstl tag using properties files for arabic and english). All pages are encoded using UTF-8. The following are configurations related to encoding:

    1. URIEncoding="UTF-8" useBodyEncodingForURI="true" is set in server.xml (Tomcat)

    2. <filter>
    <filter-name>charsetFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEnco dingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
    </init-param>
    </filter>
    in web.xml

    3. CHARACTER SET for tables in MySQL is set to UTF-8.

    4. <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> in all jsp pages.

    5. <meta contentType="text/html; charset=UTF-8"> in all jsp pages.

    I use the above configurations to write form results (possibly in arabic) to DB and retrieve the same data to jsp pages correctly (i.e. input data in the form is read and written correctly to the database).

    However, I get a wrong output (garbage) for <fmt:message> even when I tried <fmt:requestEncoding value="UTF-8">.

    The strange thing is that when I remove page directive (step 4 above), both browsers (Mozilla & IE) use ISO-8859-1 encoding for the page that appear similar to the garbage I get when settings page directive (step 4). Also, when I select UTF-8 encoding manually, the arabic string appears correctly.

    I seems to me that when forcing UTF-8, somewhere between creating and sending response, the UTF-8 enconding of arabic is translated to ISO-8859-1.

    Any help is appreciated.

    Regards,
    Ahmed Ali

  • #2
    Also make sure that the resource bundle you use for retrieving messages with fmt:message is saves as UTF-8 on the file system. If it is in another encoding it could case problems.

    Comment


    • #3
      Originally posted by mdeinum View Post
      Also make sure that the resource bundle you use for retrieving messages with fmt:message is saves as UTF-8 on the file system. If it is in another encoding it could case problems.
      That is in UTF-8 as well. Also, this does not explain the misbehaviour when settings page directive to have UTF-8 encoding. The problem still exists.

      Comment


      • #4
        I beleive this is a problem in Spring. I have the same problem when posting information using a spring based website. I have set UTF-8 as encoding everywhere possible (In a filter, all the jsp pages ).

        When I supply a euro sign in a text field and then post the information, my command bean, that uses logging, logs that the euro sign is now a ?. This happens right after the command bean is filled so it isnt a database problem or something like that. Somehow Spring isnt using UTF-8 no matter what I indicate.

        Comment


        • #5
          We had the same problem in our application and it turned out we just forgot to map the filter. As you didnt mention this above I thought I would point it out. We fixed it by addding:

          <filter-mapping>
          <filter-name>charsetFilter</filter-name>
          <url-pattern>/*</url-pattern>
          </filter-mapping>

          to the web.xml file.

          Comment


          • #6
            Did you solve your problem?

            I have the same problem and nothing helps.

            I have only problems with text that comes from my messages_de.properties file. I use <fmt:message ...> to display this text.

            JSTL in version 1.2.

            I set all possible values to UTF-8. And yes ... the property file is saved in UTF-8 format on the file system.

            Comment

            Working...
            X