File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Download bug with IE but not with FF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Download bug with IE but not with FF" Watch "Download bug with IE but not with FF" New topic
Author

Download bug with IE but not with FF

Leinad Jan
Greenhorn

Joined: Feb 18, 2009
Posts: 28
Hello,

Could you tell me what is wrong in my header that change the attachment type under IE but not under FF ?



I don't understand, on local server it works well on IE, but on a distant server, it's like if I'm losing response.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\""); The outputstream write the file like it was an HTML file. I even added 180000 milliseconds to the expiration date and it changes nothing.

Could the problem exist because I don't return null at the end of my process ?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Leinad Jan wrote:Could the problem exist because I don't return null at the end of my process ?

Are you using some MVC framework in your application or so?

Anyway, at least try invoking response.reset() beforehand. Also determine the actual response headers you got in the both browsers.
Leinad Jan
Greenhorn

Joined: Feb 18, 2009
Posts: 28
Bauke Scholtz wrote:
Leinad Jan wrote:Could the problem exist because I don't return null at the end of my process ?

Are you using some MVC framework in your application or so?

Anyway, at least try invoking response.reset() beforehand. Also determine the actual response headers you got in the both browsers.


Yes, we are using a private MVC framework based on Struts and that use Oracle ADF.

I did debug the application to know which header it used. In both cases, it select the code inside the else :



My biggest problem is that I can't reproduce the bug on my computer, it works well.

I'll try the response.reset(); before adding the header to the response. I remove the expire too, just to see if it changes something. I replace the old forward with null.

With all those changes it worked. But why was it working on my local server with exactly the same code ? I really don't understand what the problem was, but I do think it was the return null that solve everything.

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Leinad Jan wrote:
Yes, we are using a private MVC framework based on Struts and that use Oracle ADF.


It is trying to change/modify the response. You shouldn't let the MVC framework handle the response of the request for downloads. Use a plain vanilla servlet which runs completely independently or read the docs of the MVC framework in question how to let it ignore the response.

If I understand you correctly, you're using some magic mix of Apache Struts and Sun JSF (why? those are in fact competitory, you normally use the one or the other, both provides almost everything what the other also provides). So I can't give a detailed answer about how to take over the control of the response.
Leinad Jan
Greenhorn

Joined: Feb 18, 2009
Posts: 28
Bauke Scholtz wrote:
Leinad Jan wrote:
Yes, we are using a private MVC framework based on Struts and that use Oracle ADF.


It is trying to change/modify the response. You shouldn't let the MVC framework handle the response of the request for downloads. Use a plain vanilla servlet which runs completely independently or read the docs of the MVC framework in question how to let it ignore the response.

If I understand you correctly, you're using some magic mix of Apache Struts and Sun JSF (why? those are in fact competitory, you normally use the one or the other, both provides almost everything what the other also provides). So I can't give a detailed answer about how to take over the control of the response.


I wasn't there when they started the project some years ago. I'm only maintaining the application as it is now and upgrading it when it's needed. Anyway, the response reset with the return null is working fine. If it was only me, I would have build the pages in Velocity because I already done that before. But all their pages are done in JSP. My guess is that the first developpers didn't knew about Struts Velocity and choose to use JSP.

Thank you for your help !
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Its not the mime-mapping element in web.xml (or lack thereof) that is influencing this is it? We had simmilar issues with some file types (Outlook mostly) with Struts/IE6 combination. Using mime-mapping partially alleviated it.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Leinad Jan
Greenhorn

Joined: Feb 18, 2009
Posts: 28
Paul Sturrock wrote:Its not the mime-mapping element in web.xml (or lack thereof) that is influencing this is it? We had simmilar issues with some file types (Outlook mostly) with Struts/IE6 combination. Using mime-mapping partially alleviated it.


No it has nothing to do with the mime-mapping. The csv files aren't declare in my web.xml file, but it's working fine now. I only added two things, response.reset(); and return null; But maybe I should add the csv files in the mime-mapping, it wouldn't be bad to do so. In fact I thought it was already there.
Dima Chornyi
Greenhorn

Joined: Mar 25, 2009
Posts: 9
Hi Leinad,

i seem to have the same problem as you did with internet explorer downloading (and displaying inline) a file named "excelservlet" while the firefox recognizes the file properly as "worksheet.xlsx". What disturbs me specifically is that the wrong file extension causes Excel to ask me if i am sure i want to open a file where the content doesn't match the extension before dispaying it. I so far tried the "response.reset();" part, but i don't understand what you mean by returning null, could you please elaborate on that?
Leinad Jan
Greenhorn

Joined: Feb 18, 2009
Posts: 28
Dima Chornyi wrote:Hi Leinad,

i seem to have the same problem as you did with internet explorer downloading (and displaying inline) a file named "excelservlet" while the firefox recognizes the file properly as "worksheet.xlsx". What disturbs me specifically is that the wrong file extension causes Excel to ask me if i am sure i want to open a file where the content doesn't match the extension before dispaying it. I so far tried the "response.reset();" part, but i don't understand what you mean by returning null, could you please elaborate on that?


Hi Dima,

in my case, the page was reloading itself after submitting the request for the csv file. So I had an actionForward at the end of my Action method. It was the remaining code from the old version of the application. Since the page couldn't be forwarded after writing in the response, I remove the old forward to replace it by null. Which mean the page won't be reloaded by the browser. It's like making an AJAX call, you don't want to reload the whole page, so your return null in your actionForward :



Really, I don't understand why it's working fine now and it wasn't before. And like I said, I only change 2 things. Which means it's either the response.reset() or the return null.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Explanation is already given:
Bauke Scholtz wrote:
Leinad Jan wrote:
Yes, we are using a private MVC framework based on Struts and that use Oracle ADF.


It is trying to change/modify the response. You shouldn't let the MVC framework handle the response of the request for downloads. Use a plain vanilla servlet which runs completely independently or read the docs of the MVC framework in question how to let it ignore the response.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download bug with IE but not with FF