Hi
The characters (chinese) used in query parameters are Unicode characters (encoding used to accommodate character set beyond 2^8 -1 = 255 [ASCII]).
So to explain you a bit, when you send these characters or try to look these characters from the browser console, these character get converted to %encoding UTF 8 format.
Example:-
URL:- abc.com/about?q=安
Internally :- abc.com/about?q=%E5%AE%89
//Here %E5%AE%89 is % encoded UTF-8 for 安.
Online tool to get these value :- http://www.endmemo.com/unicode/unicodeconverter.php
Solution (workaround) :- Use final String param = new String(request.getParameter("param").getBytes("iso-8859-1"), "UTF-8"); [Note that this is valid if the decoding charset (URIEncoding) of the server is iso-8859-1 - otherwise this charset must be passed in.]
Actual Solution :- Decode the query string yourself, and manually parse it (as opposed to using the ServletRequest APIs) into a parameter map yourself
The problem is that the submitted query string is getting mutilated on the way into your server-side script, because getParameter() uses ISO-8559-1 instead of UTF-8. This stems from Ancient Times before the web settled on UTF-8 for URI/IRI, but it's rather pathetic that the Servlet spec hasn't been updated to match reality, or at least provide a reliable, supported option for it.
(There is request.setCharacterEncoding in Servlet 2.3, but it doesn't affect query string parsing, and if a single parameter has been read before, possibly by some other framework element, it won't work at all.)
Reference links :-
Link:-http://stackoverflow.com/questions/469874/how-do-i-correctly-decode-unicode-parameters-passed-to-a-servlet
Link:- http://stackoverflow.com/questions/3029401/request-getquerystring-seems-to-need-some-encoding
Link:- http://stackoverflow.com/questions/3029401/request-getquerystring-seems-to-need-some-encoding/3029405#3029405
Option 3:-
Send the URL as % encoded string to the Server Side.
URL:- abc.com/about?q=安
Convert this to before sending to the server :- abc.com/about?q=%E5%AE%89 using "encodeURIComponent("安");"[JavaScript function, this function would return %E5%AE%89].
Then, at server side, use:
protected static final String CHARSET_FOR_URL_ENCODING = "UTF-8";
uname = URLDecoder.decode( "%E5%AE%89", CHARSET_FOR_URL_ENCODING); System.out.println("query string decoded : " + uname); // query string decoded : 安I hope this would help you.
Thanks and Regards
Kautuk Sahni