my dog learned polymorphism*
The moose likes Java in General and the fly likes Chinese / English encoding problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Chinese / English encoding problem" Watch "Chinese / English encoding problem" New topic
Author

Chinese / English encoding problem

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Hiya,
I have a problem POSTing xml data that contains English and Chinese characters - the Chinese characters are not received correctly (eg, when I send "name=你好嗎", it is received as "name=ä½ å¥½å").

Any ideas how I can solve, without messing up the English content?

Thanks,
James
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

My standard answer is to point you at this good explanation of what is happening. Other than that, can you explain a bit more about how you are sending this data?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Thanks for the reply, Paul. The link hasn't really helped.

My code is:

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
It looks like I'm barking up the wrong tree.

The problem seems to be to do with a preceeding HTML form that submits its data to the servlet.

At the servlet, request.getCharacterEncoding() returns null.
If I add request.setCharacterEncoding("UTF-8") at the servlet, the problem seems to be fixed.

However, how do I fix my HTML form so that the character encoding info is correctly sent to the servlet (i.e., so I don't have to use request.setCharacterEncoding("UTF-8") at the servlet any more)??

Thanks in advance,
James
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
The above fix worked on Glassfish, but not on Tomcat.

Tomcat solution is well described at http://wiki.apache.org/tomcat/FAQ/CharacterEncoding for anyone else with similar problem.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Chinese / English encoding problem
 
Similar Threads
Writing Russian characters to XML file
Bringing Chinese/Japanese characters as JLabel Text
Multilingual Mail
why ActionForm shows chinese characters like ' Σ╝?Θ╗? ' ?
Localisation in HTML