• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

attachment; filename in http response doesn't work properly

 
Jiri Nejedly
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • 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.
 
Markas Korotkovas
Greenhorn
Posts: 21
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it in other browsers?
 
Jiri Nejedly
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • 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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic