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();
%>