문제

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.

도움이 되었습니까?

해결책

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:

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top