• Post Reply Bookmark Topic Watch Topic
  • New Topic

Puzzling question on encoding

 
Pat Sun
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I am working on a project that requires Chinese support, and I have encountered with something I can not explain. In my servlet, there's something like this:



Basically, it outputs whatever was inputted. UTF8 is used in all places and there was not a problem handling Chinese. But today when I 'played' with it, I found the statement
new String(inputTextChinese.getBytes("ISO-8859-1"), "UTF-8");
has no effect on the output. With or without this statement, the output was always correct.
Per my understanding, string.getBytes("ISO-8859-1") will convert it to a byt e array using Latin-1 characterset, which means Chinese characters won't be converted properly, and the information is lost. Even it's converted back with UTF-8 the already lost information will not be regained. But my test shows proper Chinese characters output all the time. Could someone shed some light on this problem? I am really confused.
btw: I am using Tomcat server for the test. Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sarah SP",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Pat Sun
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for letting me know the rules. I have changed it according to the rules. Just wonder if anyone knows the answer of the encoding question I asked originally? Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!