• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

attachment; filename in http response doesn't work properly

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using IE 8. I have a jsp page. At the bottom of the page is javascript code:

window.open('openFile.do?file=myfile.csv', '_blank', ...

which calls controller intended for opening file. It runs when jsp page loads.
My goal is that new window with 'save as' dialog should appear automatically. The controller looks like this

protected void findForward(DataActionContext actionContext) throws Exception {
super.findForward(actionContext);

HttpServletResponse response = actionContext.getHttpServletResponse();
HttpServletRequest request = actionContext.getHttpServletRequest();
String sFile = request.getParameter("file");
String sPath = ...
byte[] data = myFunctionReadingFile(new File(sPath + sFile));
ServletOutputStream outstream = response.getOutputStream();
response.setContentType("text/plain");
response.setContentLength(data.length);
response.setHeader("Content-disposition", "attachment; filename=" + sFile);
outstream.write(data);

It doesn't work properly. The window flickers and closes itself.
If I hold Ctrl, the window with dialog appears and stays, but pressing save or open closes it.
It works fine on one condition - the JS script must be run manually by clicking on button (onclick event). Then it works ok and file can be saved,

It seems to me, that it is some security reason in IE - button can do it, but loading page can't. What do you think ? Thanks.
 
Greenhorn
Posts: 21
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sounds like a pop-up blocker in IE (since it somewhat works when holding Ctrl). Try adding the server's domain in the IE pop-up blocker exception list.
 
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried it in other browsers?
 
Jiri Nejedly
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The domain is already in pop-up blocker exception list.

I tried other browsers

- FireFox is OK, save/open dialog is always shown
- Chrome always downloads file, no new window or save dialog is shown

- I finally found workaround for IE - I must hold CTRL pressed till the end, till I press Open or Save on dialog. This is acceptable for our customer too.


 
I was born with webbed fish toes. This tiny ad is my only friend:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic