Problem with Uploading file from Servlet to Client machine. 2004-02-11 - By Jasthi Bhanu Prasad (CTC)
Back Hi all, I'm using following code to upload file from servlet to client machine for saving that in the client machine. But, I could only see the dialogue box with "save" "Open" "cancel". If I click 'Open" it is reporting file corruption. If I save, I can see the size of file as 1 byte. Can any one help me by pointing the mistake in the code? or correct approach....
FileInputStream fo = new FileInputStream("c:\\tech.pdf"); response.setContentType("application/pdf");
response.setHeader("Content-Disposition","attachment; filename=output.pdf;"); javax.servlet.ServletOutputStream out = response.getOutputStream(); long avl = 0; while( (avl = fo.available()) != 0) { byte[] bytes = new byte[(int)avl]; out.write(fo.read(bytes)); } out.flush(); out.close(); fo.close();
> Thanks and Regards, > Bhanu > >
__ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ __ To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
|
|