I develop an Spring,Hibernate 5 project. I have to download Excel/pdf from another report app.
Locally in tomcat no any error or corruption. But when I deploy my project to Weblogic on Linux server, Pdf working properly but Excel data being corruption like in below image.Corupted Excel
The download takes place in jsp. And I tring to move it in servlet before.
Code part of download;
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) {
}
}
Thank you.
Problem is caused from html tags, I removed ALL html tags(html,body,head etc.) from jsp and problem was disappeared . . .