wood burning stoves 2.0*
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: File Downloads using servlets