title: Tomcat Character Encoding working differently between server and local development
body: <p>I'm having an issue with character encoding working differently in my development environment (NetBeans and local Tomcat installation) versus our server. We're using Tomcat for a server-side servlet and a Java client.</p>
  
  <p>On the server side, this code works locally on my machine:</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) {
  ...
      java.util.zip.InflaterInputStream zipIn = new java.util.zip.InflaterInputStream(request.getInputStream());
      BufferedReader in = new BufferedReader(new InputStreamReader(zipIn, "UTF-8"));
      String line = in.readLine(); // correctly encoded String
  ...
  }
  </code></pre>
  
  <p>However, on the actual server, specifying the character set breaks the code, and will only work like this:</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) {
  ...
      java.util.zip.InflaterInputStream zipIn = new java.util.zip.InflaterInputStream(request.getInputStream());
      BufferedReader in = new BufferedReader(new InputStreamReader(zipIn));
      String line = in.readLine(); // correctly encoded String
  ...
  }
  </code></pre>
  
  <p>I've tried different versions of Tomcat (7 and 8) and different versions of Java (7 and 8), I've also tried specifying the character set in the Tomcat connector (URIEncoding) and even as a JVM argument, but none of that seems to make a difference.</p>
  
  <p>When the above code executes I've checked the default character set, it's windows-1252, which is why I was specifying UTF-8 in the InputStreamReader constructor, no idea how this works on our server. The request.getCharacterEncoding() also returns utf-8.</p>
  
  <p>Does anyone have any ideas? Thanks in advance for any help.</p>