Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 Murach's Java Servlets and JSP this week in the Servlets 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?
 
Don't get me started about those stupid light bulbs.
 
subject: File Downloads using servlets
 
Similar Threads
application/vnd.ms-excel is not working for content type?
File Download from jsp
send file from java app works in browser but not wget or curl?
set Content-Type
File Download issue...