title: Java HTTP server response in utf8
body: <p>I have a http server that receive POST requests and fetches data from mysql database.<br>
  This is the relevant part of the server:<br></p>
  
  <pre><code>    @Override
      public void handle(HttpExchange he) throws IOException {
          JSONArray jsonArr = null;
          InputStreamReader isr = new InputStreamReader(he.getRequestBody(), "utf-8");
          BufferedReader br = new BufferedReader(isr);
          String query = br.readLine();
          JSONObject postData=null;
          try {
              postData=Constants.parseQuery(query);
          } catch (JSONException e) {
              System.out.println("ERROR:      SelectHandler,handle,parseQuery, on query: " + query);
          }
  //      Object t=params.entrySet().
          try {
              query=Constants.getSelectQuery(postData);
              jsonArr = MySQLQueryExecutor.getInstance().getItems(query);
          } catch (JSONException e) {
              System.out.println("ERROR:      SelectHandler,handle,getItems, on query: " + query);
          }
  
          String encoding = "UTF-8";
          String ret=jsonArr.toString();
          he.getResponseHeaders().set("Content-Type", "application/json; charset=" + encoding);
  
          he.sendResponseHeaders(200, ret.length());
          System.out.println(ret);
          OutputStream os = he.getResponseBody();
          ret= URLDecoder.decode(ret, "UTF-8");
          os.write(ret.toString().getBytes());
          os.close();
      }
  </code></pre>
  
  <p>I can see that the server handles the request and sends a response, but on the client side I get an error.<br>
  The error is due to utf8 characters in the response (hebrew chars that when I omit them the error is gone).<br>
  How can I fix this? Is this a server or client problem?</p>