wood burning stoves 2.0*
The moose likes Servlets and the fly likes Problem with URLEncoder.encode and request.getparameter with chinese characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with URLEncoder.encode and request.getparameter with chinese characters" Watch "Problem with URLEncoder.encode and request.getparameter with chinese characters" New topic
Author

Problem with URLEncoder.encode and request.getparameter with chinese characters

Shah Jenish
Greenhorn

Joined: Feb 19, 2009
Posts: 13
This is the URL that I use to invoke my servlet from my applet

Code:

http://192.168.0.67/MyServlet?p1=団

As you can see, the parameter has a unicode character 団. So I use

Code:

URLEncoder.encode ( "団", "UTF-8" ) ;

and now my URL becomes

Code:

http://192.168.0.67/MyServlet?p1=%E5%9B%A3

However, from the servlet, calling

Code:

request.getParameter ( "p1" ) ;

already return some gibberish that cannot be decoded with URLDecoder. BTW, invoking

Code:

URLDecoder.decode ( "%E5%9B%A3", "UTF-8" ) ;

does give me the original unicode character. It`s just that the servlet has garbled the parameter before it can even be decoded. Does anyone know why?

Request.gerparameter doesnt decode parameter with UTF-8?
veda bandaru
Greenhorn

Joined: Sep 14, 2006
Posts: 3
Hi,

You need to translate the character set of the parameter

Ex:


Its just an example iso code, you need to find the correct one for Chinese.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with URLEncoder.encode and request.getparameter with chinese characters