In my request Queryparameter="आकुर्डी"
. When I'm trying following
String strstring = request.getParameter("Queryparameter");
it gives "à¤à¤à¥à¤°à¥à¤¡à¥"
while I want the string "आकुर्डी"
.
How to get it? What is the problem here?
In my request Queryparameter="आकुर्डी"
. When I'm trying following
String strstring = request.getParameter("Queryparameter");
it gives "à¤à¤à¥à¤°à¥à¤¡à¥"
while I want the string "आकुर्डी"
.
How to get it? What is the problem here?
This problem is caused because you used a different character encoding to parse the request parameters than the client is using to construct the request parameters. For best compatibility with all characters known in the human world, you need to ensure that both the client and server is using the UTF-8
character encoding throughout all layers.
If it is a GET
request, then you need to configure the servletcontainer/appserver to parse the request URI as UTF-8
. You didn't tell which one you're using, but if it is for example Tomcat, then you can do so by setting the URIEncoding
attribtue of the <Connector>
element to UTF-8
:
<Connector (...) URIEncoding="UTF-8" />
If you're using a different servletcontainer/appserver, then you need to consult its documentation how to configure the character encoding of the request URI.
If it is a POST
request, then you need to instruct the HttpServletRequest
to parse the request body as UTF-8
using HttpServletRequest#setCharacterEncoding()
before collecting the request parameters.
request.setCharacterEncoding("UTF-8");
For more background information and more solutions in other areas you would need to take into account as well (such as generating the response as UTF-8
and instructing the client to use UTF-8
, so that you can keep it all uniform), you may find this blog useful: Unicode - How to get characters right?