Link to home
Start Free TrialLog in
Avatar of simi
simi

asked on

Downloading a file with servlets

Hi,

I want to be able to modify the behavior of IE when dealing with downloading files.
The actual behavior is that when the file is known(ex. .txt or .doc), the browser will read it instead of prompting the user to save as or open from the location.
There are differences between IE4 and IE5 with respect to the way those two are acting upon the downloading file, but the result is that even if I tryed different walkarounds still IE causes problems.
What I managed to get at is to use let's say a servlet(I tried it also using Cold Fusion ), that will serve the file as a byte stream.
The problem is that the Save As prompts for a file with the extension of the downloaded file but with the name of the servlet(or Cold Fusion file).
I have spied a little in the HTTP request and response, and it looks to me that what is happening is:
the browser sends a request that contains the url. The servlet will respond and the browser puts's the url as the value of the saved as file(not the whole url but just the servlet name).
I was wondering if there is anything I could do to change that to any name I want.

Thanks.
Avatar of moses123
moses123

hi simi ,

your problem is not in the user side (browser) becuase the browser has a plaginn or know to show txt or doc file it simple does so..

you can simpley change or to delete the extension of the file so the browser will not know how to open it and will ask you if you wont to save


exe     file.doc   >>>>> file.dfdf or file

but that the user (how save )must add himself the ending.




Avatar of simi

ASKER

I tried all those tricks.
The request is to have IE prompting the user to save as the file with the proper name ex: file_name.doc.
I know that changing the extension IE5 will prompt the user with the save as window, but with the name of the file with the "wroong extension"(ex. filename.doc_").
On the other hand IE4 will sniff through the file itself and still open it in spite of the extension.

It looks like not posible for same behaviour..

The mime type U have setted in servlet is this only??

response.setContentType ("application/octet-stream");
ASKER CERTIFIED SOLUTION
Avatar of Rich6176
Rich6176

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial