I've read all the questions which might be similar to this one, but I still have the same problem.
I am trying to send a file to servlet using this code:
<%@page contentType="text/html; charset=ISO-8859-2"%>
...
request.setCharacterEncoding("ISO-8859-2");
...    
<form action="CabServlet" method="POST" enctype="multipart/form-data">
                                    <input type="file" name="cab" id="cab" class="custom-file-input" lang="pl">
And then, reading it on the server side:
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("ISO-8859-2");
Part filePart = request.getPart("cab");
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.
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.
I am parsing the file from a cab to XML like that:
 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();
Any idea how to fix this?
 
    