0

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
vishvesha
  • 121
  • 1
  • 5
  • 15
  • Please provide proper tags so that appropriate audience are addressed to guide you with different approaches. – Rachel Mar 04 '10 at 04:29
  • what is your page-encoding? IIRC, look at the meta tag of your page where you can specify the encoding. what is it? utf-8? – shahkalpesh Mar 04 '10 at 04:37

1 Answers1

1

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • @Calm Storm: Not in JSP/Servlet yet, it's ISO-8859-1. In ASP.NET it is. In PHP it's far from easy/efficient. – BalusC Mar 11 '10 at 15:58