I have to download a pdf file and am using Servlets and xml, xsl. I am facing a very peculiar problem, I am able to download the file in netscape v 4.73, but not in IE v 5.0. The sample code is as mentioned below: OutputStream outStream = response.getOutputStream(); response.setContentType("application/pdf"); FileInputStream fileInput = new FileInputStream(fileName); int numOfBytes = fileInput.available(); byte byteArray = new byte[numOfBytes]; int nextByte = fileInput.read(byteArray); fileInput.close(); OutputStream outStream = response.getOutputStream(); outStream.write(byteArray); outStream.close(); Note: here response is HttpServletResponse. I have changed the setContentType to application/x-filler & application/octet-stream. These two work fine in IE but donot work in netscape. In netscape the downloaded file is saved as .html. When I retain the contentType as application/pdf, the IE download goes into a loop and hangs. CAN ANYBODY HELP ME. I am in a very crucial stage of my project. Any help in this regard would be appreciated. PS: Kindly feel free to reply to me regarding any other method by which I can download a pdf file using servlets. Regards. Vandana
Hi Bill, Thanks for the help, but to my utter dismay, setting the content length has not helped. If I keep the content type as application/pdf, The servlet is being called more than once if I use IE, but netscape does it only once. In case the content type is application/x-filler, the servlet is called once, but download is not possible. Is there any logical reason why a servlet should be called more than once if I click a link in IE which calls this servlet? Regards. Vandana. PS: I am using Apache 1.3 as my web server.
Author and all-around good cowpoke
posted 19 years ago
This sure sounds weird. Are you sure your MSIE browser is set up to understand the application/pdf MIME type? (Grasping at straws here) Bill
Hi, I want to upload the file to server and download the file to the HTML client. I m using servlets. As I think some of you people know this thing please help me. nitin
posted 19 years ago
Hi! Hope this helps you... To upload a file you can use the MultipartRequest class. Create an instance of MultipartRequest class. Set maximum file size to whatever you want multiPart=new MultipartRequest(request,saveDirectory,0x100000); // Here // saveDirectory = the url of the directory where you want to save the file // request = HttpServletRequest // 0x100000 = the post size, you could substitute this based on your own file size For this code to work, you need to import com.oreilly.servlet.*; which is available in cos.jar. You could download this jar file from the net.
To download a file you can set the content type in your servlet as setContentType = application/x-filler or application/octet-stream or application/pdf etc (there are many content types). If you are using just an html page where you need to download, you could also give the file name as a post data, i.e, after the URL/nameoffile.extention
I am having the exact same problem where IE calls the servlet multiple times, but it only happens once with Netscape. Fortunately for me, IE seems to call only 3 times, it does not go into a loop. Let us know when you find a solution. [This message has been edited by Sunil Madipalli (edited February 01, 2001).]