title: UTF-8: Hebrew charset from Ajax client to Tomcat server
body: <p><em>I am facing a problem when I transfer data [Hebrew chars] from browser to web service.
  There is no problem in Browser js side and java side but the problem occurring when I am transferring data between them.</em></p>
  
  <p>AJAX - <a href="https://xhr.spec.whatwg.org/#the-setrequestheader()-method" rel="nofollow noreferrer">setRequestHeader</a></p>
  
  <pre><code>var hebrewData = 'יאש';
  var encodeData =  encodeURIComponent( hebrew );
  
  console.log('Encoding Before :', hebrewData, '\nAfter :', encodeData);
  var xmlhttp = new XMLHttpRequest();
  
  // Method: POST; Encoding type: application/x-www-form-urlencoded (default):
  xmlhttp.open("POST","http://localhost:8088/WebApplication/Service", true);          
  xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  xmlhttp.send("data="+encodeData+"&amp;userid="userid );
  </code></pre>
  
  <p>Web Service Java file save as UTF-8</p>
  
  <pre><code>String hebrew = "חוּט";     
  System.out.println("Lan : "+hebrew);
  </code></pre>
  
  <p>I have tried these possible ways;</p>
  
  <pre><code>XMLHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  </code></pre>
  
  <p>as of java getParameter() uses ISO-8559-1 instead of <a href="http://www.oracle.com/us/technologies/java/locale-140624.html" rel="nofollow noreferrer">UTF-8</a> changed it, Tomcat <a href="http://tomcat.apache.org/tomcat-7.0-doc/config/http.html" rel="nofollow noreferrer"><code>HTTP Connector</code></a> with <code>URIEncoding="UTF-8" (or) useBodyEncodingForURI="true"</code></p>
  
  <pre><code>In servlet « request.setCharacterEncoding("UTF-8");
  tomcat server.xml « &lt;Connector port="8010" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" /&gt;
  </code></pre>
  
  <p>but I am unable to get the correct output.</p>