February 1st, 2003, 03:49 PM
I wrote a servlet that would let a user download an XML file. The servlet calls a utility class passing it the HttpServletResponse object. The utility class then writes then writes the XML file to the ServletOutputStream corresponsing to the HttpServletResponse object. Before I write it, I perform the following steps.
res.setHeader("Content-Type", "attachment;" + "filename=" + filename + ";");
Then I wrte to the ServletOUtputStream. This works fine in Netscape and IE. The browser opens up a save as dialog box, and the user can save the file as the name specified above (filename).
This has been a big problem to me. I hope someone can help.
February 1st, 2003, 07:04 PM
Any chance we can see the links to the page and/or some code?
Also, I believe the correct mime type for an unspecified binary file is application/octet-stream
I also just noticed that you are using content-type as the header you are specifying the filename in. I believe that should be Content-disposition.
Last edited by Nemi; February 1st, 2003 at 07:11 PM.
October 2nd, 2003, 05:22 PM
I'm experiencing the same problem. Have you ever figured out a solution? Thanks
October 2nd, 2003, 06:23 PM
figured it out....use
resp.setHeader("Content-Disposition","inline; filename=\"" + file.getName() + "\"");
inline replaces attachement is the key
October 10th, 2003, 09:49 AM
Hey, i have the same problem. so i tried putting the inline instead of attachment, but now it opens the file directly in excel without asking whether i want to view it or save it. and it doesn't even recognise the file properly. it's a csv file with colums seperated with comas, and yet Excel opens it all in one colums. the file doesn't even have a name, and when i try to save it it doesn't give a name either... is that normal?
October 10th, 2003, 10:03 AM
Usually if you want to prompt the user for what they want to do with the file, you use the word "attachment" instead of "inline". inline will try and open it in the browser normally (or whatever is setup to open that type of file).
Last edited by Nemi; October 10th, 2003 at 10:06 AM.
October 10th, 2003, 10:09 AM
yeah that's true, but the problem is, if i use attcahment i get an access denied error after saving the file. it's the same problem that svelez has.
October 10th, 2003, 11:41 AM
Ok, I think I know of this problem. I think it is a known IE problem. I assume you download this file using a link? If so, what does it do if you provide a different target for the link? Something like target="_blank"?
October 10th, 2003, 12:01 PM
I have to leave right now, but i'll try it on monday and let you know what happens. thx for ur help!
October 13th, 2003, 10:06 AM
Ok, I don't see the actual thing you click on to initate the download. Is it a link, button, graphic? I assume it is a button because of the ChangeButton function, however, I don't see this function listed anywhere. Realize that if you don't post all the relevant code I cannot give you good answers.
Having said that, it looks like it initiates the file download by setting the location of the document. You are going to have to change the way this is done. Either use a link or a hidden form. I would suggest a hidden form. You can get the form by name in the same function that currently initiates the download and submit it. You can set the action and the target of the form.
I am not saying this is guaranteed to work. I am merely suggesting it as a possible solution. I have not tested it.
If you set the target to a new, non-existing window, a new window should open, but I believe that if a file save dialog comes up the new window closes automatically.
October 16th, 2003, 03:13 AM
I actually figured it out! like u guys said it's a known IE problem and i had to work around it. I used the IFRAMEs like it says on http://support.microsoft.com/default...;en-us;Q306673 and it works! it was a bit annoying tho cos the iframes work only with IE and not netscape so i had to do them seperately.
Anyways, thx alot for the help Nemi and everyone!
Last edited by Queen_Amidala; October 16th, 2003 at 03:15 AM.
October 16th, 2003, 09:52 AM
Thanks for posting the fix!
October 22nd, 2003, 10:39 AM
Has anyone found another solution, one that is browser-independent?
October 22nd, 2003, 12:05 PM
October 22nd, 2003, 03:03 PM
EDIT: I had a suggestion, but I realized it would not work. I also second Amidala's idea of using an if statement.
Last edited by Nemi; October 22nd, 2003 at 03:17 PM.