on 03-12-2015 10:41 AM
Hi Experts,
I am downloading an excel file which is stored at the MII server using JSP file. I am using the below code for the same. I am able to download the excel file successfully but when I open the same I get some junk value as content. I mean to say the content is not at readable format. I have tested the java code using standalone program where it worked successfully.
I tested this JSP at MII 12.2 and MII 14.0 and both provided same result. I have attached the screenshot of excel how it looks after opening
I want to know is this a problem with Netweaver web server?. I mean the way it runs JSP. Unfortunately I could not test this on another web server
Any help on this is very much appreciated.
<%
String filePath = "C:\\myfile.xls";
try
{
FileInputStream in = new FileInputStream(filePath);
response.setContentType("application/vnd.ms-excel");
response.addHeader("content-disposition","attachment; filename=" + filePath);
int octet;
while((octet = in.read()) != -1)
out.write(octet);
in.close();
out.close();
}
catch(Exception e)
{
out.println("Exception occured:"+e);
}
%>
Thanks
Shaji
You can try response.setContentType("APPLICATION/OCTET-STREAM");
Regards,
Christian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Christian,
Thanks for your response.
I tried that as well but same result. I get a alert message as below while opening the file.
"Excel cannot open the file Demo.xls because the file format or file extension is not valid. Verify that file has not been corrupted and that the file extension matches the format of the file"
I am trying to run the same file on another web server such as tomcat and see if the issue persist.
Thanks
Shaji
The attached jsp worked for me. A jsp is like an inside out servlet so any characters or newlines or anything outside your jsp scriptlet will be output by the server. This includes newlines after scriptlet etc. If you are trying to return a binary file with a jsp it will corrupt the file. I think this may be causing your issue.
Regards,
Christian
User | Count |
---|---|
10 | |
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.