title: How to use utf-8 in Servlet handler for request parameters?
body: <p>I have a default installation of Tomcat 8.5.6. It seems like UTF-8 encoded requests are not being interpreted correctly, even though the docs say the default (if not in strict mode) should be UTF-8 everywhere these days. My java POST requests look like:</p>
  
  <pre><code>HttpPost post = new HttpPost(url);
  post.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
  ...
  </code></pre>
  
  <p>Testing, I see the tilde character ñ is not decoded correctly in my servlet handler:</p>
  
  <pre><code>public class MyServlet extends HttpServlet {
      protected void doPost(HttpServletRequest request, ...) {
          String tildeTest = request.getParam("foo"); // no good.
      }
  }
  </code></pre>
  
  <p>if I explicitly set the encoding on the request before access, it decodes properly:</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, ...) {
      request.setCharacterEncoding("UTF-8");
      String tildeTest = request.getParam("foo"); // works!
      ...
  }
  </code></pre>
  
  <p>so I'm not sure if:</p>
  
  <ol>
  <li><p>Tomcat 8.5.6 is not really using UTF-8 everywhere, and I need to set that manually in the config files somewhere.</p></li>
  <li><p>My http request is missing some header which tells Tomcat which encoding to use - perhaps the http post is defaulting to some other encoding which Tomcat is just honoring.</p></li>
  </ol>
  
  <p>Anyone know which one?</p>
  
  <p>Thanks</p>