Image

Imagebanana wrote in Imagejava_dev

It's all Greek to me


I have a <%= expr %> tag in a JSP page that inserts text that's come from a database.
If the text is in English all is well.
When the text is Chinese, garbage comes out.



In the servlet response API there's a method for getting the character encoding, but no method for setting it.
Instead you can set the response locale, which according to the Javadoc includes "setting the headers (including the Content-Type's charset) as appropriate."
So I could set the response locale to Chinese, but that would mean that other languages stopped displaying corectly.



What I really want is to set the character encoding to UTF-8, then (assuming that I set the appropriate response header) it's the browser's job to display the text correctly.
But as I can only set the locale, what locale will get me a UTF-8 encoding?
Or is there some other way of controlling character-to-byte conversion in the response?




As an aside for those who are still following this, I've noticed that it I tell the browser to interpret the page as UTF-8, the Chinese comes out right (or at least, as I can't read Chinese, it at least looks like Chinese).
However, doing this makes French words with accented letters have Chinese characters in the middle. 8~(