I am trying to get it via getParameter() method.
getParameter
and handling of input encodings in Servlet is broken in general. You get ISO-8559-1 whether you want it or not (and you generally don't).
You can work around this and get UTF-8 for query string parameters by:
Container-specific configuration options (eg Tomcat
URIEncoding
).Grabbing the raw
request.getQueryString()
and passing its pieces intoURLDecoder.decode(..., "utf-8")
manually instead of relying ongetParameter
. Only if you are taking this route do you need to worry aboutURLDecoder
yourself.Fixing up the mis-decoding of the
getParameter
output by encoding the bad value back to the original bytes it came from (using ISO-8859-1) and then decoding it as UTF-8, egnew String(request.getParameter("param").getBytes("iso-8859-1"), "utf-8")
.
See this question for background.