File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes File Downloads using servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "File Downloads using servlets " Watch "File Downloads using servlets " New topic
Author

File Downloads using servlets

Chavali Raghu
Greenhorn

Joined: Jul 31, 2002
Posts: 1
Problem downloading a file through the servlet.
The file download happens, but shows only 0 bytes as its content.
sample code of the setting of the headers is shown below:
response.setHeader("Content-Length",String.valueOf(fDownloadFile.length()));
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;Filename=" + fDownloadFile.getName());

Please tell me if the reason for this not happening.
rgds,
Raghu
Peter Storch
Ranch Hand

Joined: Jun 12, 2003
Posts: 74
I don't know about the "Content-Disposition" header.
Don't you have to open the input stream of your file and write the bytes to the response output stream of the servlet yourself?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Downloads using servlets
 
Similar Threads
File Download from jsp
File Download issue...
send file from java app works in browser but not wget or curl?
set Content-Type
application/vnd.ms-excel is not working for content type?