Pergunta

i am using spring 3, JSF 2 , MYSQL, Hibernate, and Heidi SQL is the GUI tool for the database and i am having an encoding problem with Arabic characters is that Arabic words is inserted in the database as ?????????? and appears in the view in the same form.

so here's my encoding configuration:

1- Database:

  • Character set: utf 8

  • Collation: utf8_general_ci

2- Spring:

i am using the following filter:

<filter>
    <filter-name>encoding-filter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>utf-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encoding-filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

3- JSF:

As far as i know: Facelets uses UTF-8 by default.

4- Hibernate:

here's the connection url for the database:

jdbc:mysql://127.0.0.1:3306/mydb?zeroDateTimeBehavior=convertToNull&useUnicode=true&connectionCollation=utf8_general_ci&characterSetResults=utf8

please advise if i am missing something in the configuration.

Foi útil?

Solução

You forgot the characterEncoding=UTF-8 parameter in your JDBC URL. Here's the revised JDBC URL with the minimum required parameters to let it handle UTF-8 properly:

jdbc:mysql://127.0.0.1:3306/mydb?useUnicode=true&characterEncoding=UTF-8

See also:

Outras dicas

if you use tomcat you will need to add the following argument to configuration Arguments:

-Dfile.encoding=UTF-8 

in addition to the above hibernate configuration.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top