title: Why does POST not honor charset, but an AJAX request does? tomcat 6
body: <p>I have a tomcat based application that needs to submit a form capable of handling utf-8 characters. When submitted via ajax, the data is returned correctly from getParameter() in utf-8. When submitting via form post, the data is returned from getParameter() in iso-8859-1. </p>
  
  <p>I used fiddler, and have determined the <em>only</em> difference in the requests, is that <strong>charset=utf-8</strong> is appended to the end of the <strong>Content-Type</strong> header in the ajax call (as expected, since I send the content type explicitly).  </p>
  
  <p>ContentType from ajax:
  "application/x-www-form-urlencoded; charset=utf-8"</p>
  
  <p>ContentType from form:
  "application/x-www-form-urlencoded"</p>
  
  <p>I have the following settings:</p>
  
  <p>ajax post (outputs chars correctly):</p>
  
  <pre><code>$.ajax( {
    type : "POST",
    url : "blah",
    async : false,
    contentType: "application/x-www-form-urlencoded; charset=utf-8",
    data  : data,
    success : function(data) { 
    }
   });
  </code></pre>
  
  <p>form post (outputs chars in iso)</p>
  
  <pre><code> &lt;form id="leadform" enctype="application/x-www-form-urlencoded; charset=utf-8" method="post" accept-charset="utf-8" action="{//app/path}"&gt;
  </code></pre>
  
  <p>xml declaration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p>Doctype:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  </code></pre>
  
  <p>meta tag:</p>
  
  <pre><code>&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
  </code></pre>
  
  <p>jvm parameters:</p>
  
  <pre><code>-Dfile.encoding=UTF-8
  </code></pre>
  
  <p>I have also tried using <strong>request.setCharacterEncoding("UTF-8");</strong> but it seems as if tomcat simply ignores it. I am not using the RequestDumper valve. </p>
  
  <p>From what I've read, POST data encoding is mostly dependent on the page encoding where the form is. As far as I can tell, my page is correctly encoded in utf-8.</p>
  
  <p>The sample JSP from this page works correctly.  It simply uses <strong>setCharacterEncoding("UTF-8");</strong> and echos the data you post.    <a href="http://wiki.apache.org/tomcat/FAQ/CharacterEncoding">http://wiki.apache.org/tomcat/FAQ/CharacterEncoding</a></p>
  
  <p>So to summarize, the post request does not send the charset as being utf-8, despite the page being in utf-8, the form parameters specifying utf-8, the xml declaration or anything else. I have spent the better part of three days on this and am running out of ideas.  Can anyone help me?</p>