spvijay wrote:
Hi All..
We have some difficulty in storing UTF-8 characters in out Java App (Struts-Hibernate-MYSQL).The request charset and the DB charset are set correcly to UTF-8.
You don't seem to be paying attention the to charset used by the web page. Your UTF-8 characters may be received by the browser in UTF-8, but that doesn't mean they are rendered as UTF-8, or sent back to the server as UTF-8.
For example:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
It's possible to intiate a request via xhr specifying charset in the headers that doesn't match your current page's charset, which will lead to trouble.
spvijay wrote:
When a user enters UTF-8 charcters,they are stored properly in the DB.
While retrieving from the DB thru Hibernate,the collection seems to ignore UTF-8 charcters and are rendered wrongly on the UI.
If this value is used to store back in the DB,the UTF-8 characters are lost.
That's pretty weird. I can't think why a user entering data might produce different encoding to the page being populated with data and that data saved, unless your UI components are somehow mangling the data. Are you using plain HTML <input> tags, or some Javascript client library that might be performing some re-encoding? How exactly is your request for data initiated, and the result put into the UI?
I had lots of trouble recently with a latin-1 database, read by a PHP script, which was called by a Java app server and fed to a web browser, and then the whole thing again in reverse. For you, Java itself should be able to deal with UTF-8 transparently, if all your data is in that encoding you won't have trouble at that layer. I ended up having to use "byte[] utf8bytes = String.getBytes(targetCharset)" and "String targetversion = new String(utf8bytes, targetCharset)" .. but in your case, if your data is clearly getting to and from the UI correctly, the encoding trouble must be in your web layer and nothing to do with your Java server.
Nick