Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

download files through JSP

843835Apr 13 2002 — edited Mar 1 2005

Hi,

I'm using the following jsp page to download pdf files. For some reason the pdf size is bigger than it should, hence it got corrupted!

It might be that the jsp page itself is added to the attachment!!! I'm not sure..

Can some one tell me why is this happening and how can I solve this problem?

Thanks
Naji


<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>


<%
String fname=request.getParameter("fileName");
String folder1="/opt/netscape/server4/devdocs/DMEGOV/images/CSSB00-08-08.pdf";
response.setContentType("application/x-filler");
System.out.println(fname);
response.setHeader("Content-Disposition","attachment; filename=\""+fname+"\";");
ServletOutputStream stream = response.getOutputStream();
BufferedInputStream fif =new BufferedInputStream(new
FileInputStream(folder1));
byte buffer[]=new byte[65536];
int data=0;
stream.flush();
while((data = fif.read(buffer)) != -1) {
stream.write(buffer,0,data);
}
fif.close();
%>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2005
Added on Apr 13 2002
8 comments
427 views