Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open/Save Dialog for attached file 1

Status
Not open for further replies.

Diancecht

Programmer
Jan 8, 2004
4,042
ES
Hi all.

I'm developing a servlet that tries to attach a file in the response. Everything is running ok, the file gets attached and the client browser shows the Open/Save dialog. The problem comes here.

When using IE5.0 or IE6.0 I need to press twice the Open button to get the file downloaded. I thought at first that it was an IE problem, but now I'm suspecting I'm making a mistake at some point while attaching the file.

I've also seen this problem surfing the wev trying to download files from some sites. I've been searching some forums about this with no results.

Anyone has any clue on what's happening?

Thanks in advance.

Dian
 
How are you writing the "attachment" ? Something like :

Code:
InputStream is = ... read the stream
byte[] data = new byte[size];
is.read(data);
OuputStream out = response.getOutputStream();
response.setContentType(mimeType);
out.write(data);
 
Fisrt of all, thanks for your reply.

I add the headers

response.setHeader("Contentdisposition",contentDisposition);
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);

and then I attach the file as you suggested.

I think this is all ok. The problem seems to be a bug on the Internet Explorer 5. I was wondering if anyone found a way to make the IE work properly without installing the patch, as long as I cannot know which browser will have the client.

Cheers.

Dian

 
Do you defintely set the mime content type of the response ...
 
Yupp, I do.

response.setContentType(contentType);

In fact, when I click te second time the Open button, it downloads and opens the file correctly. I hate when you do everything ok and the browser fails, and it's worse when you spend a lot of time screaming around thinking it's you r fault.

Cheers.

Dian
 
If you are dumping the file to the screen, you always use something like this :

<embed src=&quot;/apps/servlet/FileServlet?file=<%=file%>&quot; type=&quot;application/pdf&quot; width=&quot;100%&quot; height=&quot;100%&quot;>

rather than calling the servlet direct ...
 
Would be nice, indeed, but the servlet is just a small part of a big channel arquitecture and it has to be generic purpose. I have no idea of which kind of entity will invoke the servlet and I have to be prepared for thw worst case.

The good parts is that, since it's a bug un the browser, I always can say the &quot;blame Microsoft people, not me&quot;, but I'd prefer to avoid it. I love doing good work.

By the way, you gained a star for your patience.

Cheers.

Dian
 
Ahhh, the joys of generic tools.

Cheers !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top