File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » JSP
Bookmark "File Downloads using servlets " Watch "File Downloads using servlets " New topic

File Downloads using servlets

Chavali Raghu

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-Disposition","attachment;Filename=" + fDownloadFile.getName());

Please tell me if the reason for this not happening.
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:
subject: File Downloads using servlets
It's not a secret anymore!