PDA

View Full Version : utf8 encoding decoding



sj137
20 Jun 2007, 12:48 AM
Hi I've been reading through the forum threads on this topic and i'm still a little confused, therefore i was hopeing someone could point me in the right direction

I'm sending utf8 data from the browser to the (Java) server using the JSON.encode method but text at the server end isn't being decoded properly...

I found in a post from Animal the following link for decoding a bytestream in Java (to UTF8):

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#String(byte[],%20int,%20int,%20java.lang.String)

however I'm using a servlet and from the HttpServletRequest.getParameter method I only get a string, does anyone know how to decode the request params in Java from the String?

Many thanks in advance

sj137
20 Jun 2007, 12:57 AM
check out:

http://weblogs.java.net/blog/joconner/archive/2005/07/charset_traps.html

or just add

request.setCharacterEncoding("UTF-8");

to you r doPost method in your servlet

;)