Post a UTF-8 string to a servlet using jquery
<p>I'm trying to POSt a UTF-8 string to my servlet (hosted in TomCat) but the string read on the server side is not UTF-8.  I've verified via firebug that the ajax header's content-type has the utf-8 encoding set. I'm posting "MÉXICO" to the server but I'm receiving "MÃ‰XICO".</p>

<pre><code>$.ajaxSetup({ 
    scriptCharset: "utf-8" , 
    contentType: "application/x-www-form-urlencoded; charset=UTF-8"
});


$.ajax({
  url: "SetData",
  type: 'POST',
  data: 'MÉXICO',
  success: function(){
      console.log('Data set');
  }
});
</code></pre>

<p>Here's the java code in the servlet</p>

<pre><code>request.setCharacterEncoding("UTF-8");
BufferedReader reader = new BufferedReader( new InputStreamReader( request, "UTF-8" ) );        
char[] chr = new char[5];
reader.read( chr );
builder.append( chr );
</code></pre>

<p><strong>UPDATE 1</strong></p>

<p>I changed the posting data in js to encodeURIComponent('MÉXICO') but the server still reads "MÃ‰XICO".</p>

<p>But, if I get the string value of encodeURIComponent('MÉXICO') i.e. 'M%C3%89XICO' it works!
I'm zapped! Any idea why this should work?</p>

<pre><code>$.ajax({
  url: "SetData",
  type: 'POST',
  //data: 'MÉXICO', ** does not work
  //data: encodeURIComponent('MÉXICO'),  ** does not work
  data: 'M%C3%89XICO',  //works !!!!
  success: function(){
      console.log('Data set');
  }
})
</code></pre>

<p>;</p>
