471,316 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

dynamic file download from servlet

I need to allow a user of my web application to download
a dynamically generated file, in this case from something
I've stored in a database. I am experimenting with this
and the file to download happens to be a pdf file. When
I hit the link from an IE6 browser it pops up a dialog
box asking whether I want to open or save it, which is
exactly the behavior I want. However, when I press the
open button, Acrobat Reader opens (cool) but then it fails
with:

There was an error opening this document, The file does not exist.

When I click on the same link on my linux box, xpdf handles it
just fine.

I think it has something to do with the HTTP header, but I am
not sure. The following is the code of interest:

AttachmentListItem attachment =
EmailSQL.getAttachmentListItem(connection, 3, 1);
response.setContentType(attachment.getContentType( ));
byte[] data =
EmailSQL.getAttachmentBytes(connection, 3, 1);
response.setContentLength(data.length);
response.setHeader("Content-Disposition",
"attachment; filename=" + attachment.getFileName());
ServletOutputStream out = response.getOutputStream();
out.write(data);
out.flush();
out.close();

Any idea on how to get this to work on my windows box?

Dean Hoover

Jul 17 '05 #1
0 4901

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Patrick | last post: by
1 post views Thread by Vasil Slavov | last post: by
1 post views Thread by Matthew Flower | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.