I am working on a Spring MVC + Hibernate application, use MySQL (version 5.0.51a) with the InnoDB engine.
The problem occurs when I submit a form with Cyrillic characters. As a result, the database contains meaningless characters in an unknown encoding.
All JSP pages, databases (+ tables and fields) created using UTF-8. The Hibernate configuration also contains a property that sets the encoding to UTF-8.
I solved this by creating a filter that encodes the contents of the request using UTF-8. Sample code:
…
encoding = "UTF-8";
request.setCharacterEncoding(encoding);
chain.doFilter(request, response);
…
But this noticeably slows down the application.
Interestingly, executing the insert request directly from the application (i.e., starting from Eclipse as a Java application) works fine.
UPD
, - .
CharacterEncodingFilter. , !
<filter>
<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>