I have a web app that gathers some data from the user and saves them to a mysql database. The problem is that for a String like “Ajánlat kiküldése”, what gets stored to the database is “Ajánlat kiküldése”.
For my database, i have DEFAULT CHARACTER SET utf8. For my tables i have DEFAULT CHARSET=utf8.
In my hibernate.cfg.xml i have:
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">UTF-8</property>
<property name="hibernate.connection.charSet">UTF-8</property>
If I enter “Ajánlat kiküldése” directly into the database using a mysql client, the text gets stored correctly. SO somewhere along the way inside my application the text gets changed.
I have this in my jspx page:
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
For my form I use sutrts html taglib and the code is very simple:
<html:form action="/submitAddProject">
<table>
<tr>
<td>name</td>
<td>
<html:text property="projectNameToAdd"/>
<td>
etc.
On submit, when I do myForm.getProjectNameToAdd, I have a different text than the one I enter in the form. (Ajánlat kiküldése instead of Ajánlat kiküldése )
You can try to create the following filter:
UPDATE:
You need to create Utf8EncodingFilter class, import Filter interface, exception, etc. (any modern IDE will do this for you). Then you need to add this filter into your deployment descriptor (can be found at WEB-INF/web.xml) using the following syntax:
You can read more about filters here: http://www.ibm.com/developerworks/java/library/j-pj2ee10.html