Linux/weblogic Excel 下载时出现损坏的字符
Linux/weblogic Excel download giving corrupted characters
我开发了一个 Spring,Hibernate 5 项目。我必须从另一个报告应用程序下载 Excel/pdf。
本地 tomcat 没有任何错误或损坏。但是当我将我的项目部署到 Linux 服务器上的 Weblogic 时,Pdf 工作正常但 Excel 数据损坏,如下图所示。Corupted Excel
下载发生在 jsp。我之前尝试将它移动到 servlet 中。
下载代码部分;
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) {
}
}
谢谢。
问题是由html标签引起的,我删除了ALL html标签(html,body,head etc.) 来自 jsp,问题消失了。 . .
我开发了一个 Spring,Hibernate 5 项目。我必须从另一个报告应用程序下载 Excel/pdf。
本地 tomcat 没有任何错误或损坏。但是当我将我的项目部署到 Linux 服务器上的 Weblogic 时,Pdf 工作正常但 Excel 数据损坏,如下图所示。Corupted Excel
下载发生在 jsp。我之前尝试将它移动到 servlet 中。
下载代码部分;
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) {
}
}
谢谢。
问题是由html标签引起的,我删除了ALL html标签(html,body,head etc.) 来自 jsp,问题消失了。 . .