Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chinese / English encoding problem

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply, Paul. The link hasn't really helped.

My code is:

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic