• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Download file - problem with IE?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm uploading (binary) files to a BLOB (most of the time word or pdf).
When I try to download a file a came across the following:
- After I click on a file to be downloaded (a html:link calling appropriate action) I get this Open/Save dialog.
- When I click Open, Word displays a warning that a file could not be found
- When I try again, Word opens the file just fine

This is only the case with IE. With Opera it works the first time. But I need it to work in IE.

In my Action:

response.setContentLength( (int) fileinfo.getFileSize());
response.setContentType("application/x-file-download");
response.setHeader("Content-disposition",
"attachment; filename="
+ fileinfo.getFilename());

ServletOutputStream outStream = response.getOutputStream();

dao.getFileData(id, outStream);
outStream.flush();
return null;

Any suggestions?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've run into the same problem, and in my case, the problem was related to the browser cache. Most of the time, I have code to prevent the browser from caching my pages, so that I'm always sure to get fresh information. However, when downloading it's important that browser caching is enabled. If a user selects "open", Internet Explorer attempts to open the document from the browser cache. If you've instructed the browser not to cache the document, it isn't there to open. Try adding the following to your download action, and see if it fixes the problem:
 
Milan Tomc
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Merrill, it does work indeed. Thanks for your reaction and help.


But,...
Could you also explain why did it work without it in Opera?
With other words, will this allways work independently of browser settings? Or should I warn the users to set their browsers in a certain way?

I also have the following in my struts-config.xml

<controller
processorClass="org.apache.struts.tiles.TilesRequestProcessor"
bufferSize="4096" debug="0" nocache="true"/>

To prevent dirty reads as a result of a back button.

Thanks again,
Milan
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know much about the inner workings of Opera, but I supect that the reason Opera works and IE doesn't is that Opera doesn't rely on the browser cache when a user opts to open a downloaded file while IE does.

You can keep your nocache="true" setting in the struts-config.xml file. By placing the code that I gave you in the action, you are overriding this option just for the one action, while all others continue to instruct the browser not to cache the document. This technique does not rely on the users setting their browsers in any certain way, so you don't need to worry about that.
 
Milan Tomc
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
muchos gracias
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic