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.
On the server side, this code works locally on my machine:
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
...
}
However, on the actual server, specifying the character set breaks the code, and will only work like this:
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
...
}
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.
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.
Does anyone have any ideas? Thanks in advance for any help.