Problem with encoded UTF8 parameter when calling request.getParameterValues

I'm losing some parts of my parameters when I get to the servlet.
Using the java.net.URLEncoder on an English/Chinese UTF-8 string combination, I created a URL with a parameter "pk". I use this in an HTML page that calls a servlet. Here is what I set the parameter equal to:
pk=GUEST.%E6%88%3F%E9%83%BD%E8%88%B9%E5%3F%95%E4%BD%3F%E8%A7%84%E6%A0%BC
My URL looks like the following:
http://localhost/servlets/MyServlet?pk=GUEST.%E6%88%3F%E9%83%BD%E8%88%B9%E5%3F%95%E4%BD%3F%E8%A7%84%E6%A0%BC
When this gets to the servlet side, I lose all of the chinese parts of the String when I call request.getParameterValues("pk") for this string. This is the case even if I convert the string to UTF8 using getBytes("UTF8").
String[] pks = request.getParameterValues("pk");
pks.length = 1
pks[0].length() = 6
pk[0]=GUEST.
Any clue why?
My page has a charset of utf-8 and other pages with using posts work fine. Unfortunately my request must be a get in this situation.

Try this standard tomcat workaround...
String[] tmppks = request.getParameterValues("pk");
String [] pks = new String[tmppks.length];
for(int i=0; i<tmppks.length; i++)
pks[i] = new String(tmppks.getBytes("ISO-8859-1"),
), "UTF-8");Hi,
I am working in JSP.
If I don't convert the string to UTF-8 format, then even though I am setting the charset to UTF-8 in jsp page, it is not giving the correct parameter values.
Is there any way other than converting the string from "ISO-8859-1" to "UTF-8", in order to get the string in UTF-8 format i.e., to get string in UTF-8 format directly from request.getParameter method?
Thanks & Regards,
Kavitha.

Similar Messages

Maybe you are looking for