title: How to fix encoding in multiform/form-data on Tomcat?
body: <p>I've read all the questions which might be similar to this one, but I still have the same problem.</p>
  
  <p>I am trying to send a file to servlet using this code:</p>
  
  <pre><code>&lt;%@page contentType="text/html; charset=ISO-8859-2"%&gt;
  ...
  request.setCharacterEncoding("ISO-8859-2");
  ...    
  &lt;form action="CabServlet" method="POST" enctype="multipart/form-data"&gt;
                                      &lt;input type="file" name="cab" id="cab" class="custom-file-input" lang="pl"&gt;
  </code></pre>
  
  <p>And then, reading it on the server side:</p>
  
  <pre><code>response.setContentType("text/html;charset=UTF-8");
  response.setCharacterEncoding("ISO-8859-2");
  Part filePart = request.getPart("cab");
  </code></pre>
  
  <p>I know that using ISO-8859-2 encoding is outdated, but it is a pretty old project and I can not modify it ( I can in my files, but I can not change it globally ). I am also new to using JSP and servlet stuff.</p>
  
  <p>The problem which I have is that when I'm receiving a file on Tomcat which is set up on windows everything is ok. But when I try to run my code on Tomcat set on Linux it doesn't work - I receive a file with bad encoding, which makes polish characters "śćź..." appear as "?". The file which I'm sending is a .cab archive, and after reading it and saving it to XML file encoding problems happen. </p>
  
  <p>I am parsing the file from a cab to XML like that:</p>
  
  <pre><code> DocumentBuilderFactory builderFactory = 
          DocumentBuilderFactory.newInstance();
          DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
          Document doc = docBuilder.newDocument();
          // Root element
          Element root = doc.createElement("cabparser");
          root.setAttribute("version", getVersion());
          doc.appendChild(root);
          ...
          // Parse XML file to String format and then return it
          TransformerFactory factory = TransformerFactory.newInstance();
          Transformer transformer = factory.newTransformer();
          //transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
          DOMSource domSource = new DOMSource(doc);
          StringWriter writer = new StringWriter();
          StreamResult streamResult = new StreamResult(writer);
          transformer.transform(domSource,streamResult);
  
          return writer.toString();
  </code></pre>
  
  <p>Any idea how to fix this?</p>