Hi all,
I am facing a problem with a client servlet application that i am developing.
my android client communicates with the servlet using
org.apache.http.HttpEntity
and
org.apache.http.HttpResponse
it all works fine, but when i am trying to sent over some data in Greek, i am getting an error. It seems that the servlet doesnt recognise the greek characters, instead it prints ??? on the console. The other way round works just fine. Greek letters are received OK by the client.
here is a part of my code.
Android Client
Here params[0] is a string containing Greek letters. if i print this out on the console, i am reading the string just fine.HttpPost httppost ; HttpClient httpclient; .... httpclient = new DefaultHttpClient(); httppost = new HttpPost("http/local..." ); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("command", "getB")); nameValuePairs.add(new BasicNameValuePair("city", params[0])); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); HttpEntity ht = response.getEntity();
The servlet
Here the city variable if printed on the console is not what expected. I am getting ?? instead of the greek letters.protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); String command = request.getParameter( _command ); String city=request.getParameter(_city); .....}
I have tried to use response.setCharacterEncoding("UTF-8"), but is not acceptable on the client side.
Any help pls?