Linux / weblogi c Excel скачать с поврежденными символами - PullRequest
0 голосов
/ 27 января 2020

Я разрабатываю проект Spring, Hibernate 5. Я должен скачать Excel / PDF из другого приложения отчета.

Локально в tomcat нет ошибок или повреждений. Но когда я развертываю свой проект на Weblogi c на Linux сервере, Pdf работает правильно, но данные Excel повреждены, как на картинке ниже. Corupted Excel

Загрузка происходит в jsp. И я пытаюсь переместить его в сервлет раньше.

Код части загрузки;

            response.reset();
            o = response.getOutputStream();

            String typeStr = "application/vnd.ms-excel"; 
            typeStr = typeStr + "; charset=UTF-8";
            response.setContentType(typeStr);
            response.setHeader("Content-disposition","attachment; filename=\"" + downloadName + "\"" + ".xls");
            url1 = new URL(reportUrl);
            HttpURLConnection http = (HttpURLConnection) url1.openConnection();

            response.setHeader("User-Agent", "Mozilla/5.0");
            response.setHeader("Accept-Language", "en-US,en;q=0.9");
            response.setHeader("Content-Language", "en");
            response.setHeader("Transfer-Encoding", "chunked");
            response.setHeader("Accept-Encoding", "gzip, deflate");
            http.setRequestMethod("GET");
            http.setRequestProperty("Content-type", typeStr);
            http.setRequestProperty("Accept-Encoding", "identity");

            http.setDoOutput(true);
            http.setDoInput(true);
            http.connect();

            i = http.getInputStream();

            byte b[] = new byte[1024];
            while (true) {
                int length = i.read(b, 0, b.length);
                if (length < 0)
                    break;
                o.write(b, 0, length);
            } // while()

            http.disconnect();
            o.flush();
            o.close();
            i.close();
        } catch (Exception ex) {
            ex.printStackTrace();
            try {
                i.close();
                o.close();
            } catch (Exception e) {
            }
        }

Спасибо.

1 Ответ

0 голосов
/ 24 февраля 2020

Проблема вызвана тегами html, я удалил теги ALL html (html, тело, голова и c.) Из jsp и проблема исчезла , .

...