You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eric Hodges <EH...@USDataworks.com> on 2004/08/27 18:17:22 UTC

Question about downloading files from a Struts servlet

I have a Struts form and action that downloads a file to the client.  The
servlet code looks like this:

  response.reset();
  AdminSetupForm setupForm = (AdminSetupForm) form;
  response.setContentType("application/download");  // also tried
"application/octet-stream", "junk/xml", etc.
  response.addHeader("Content-disposition", "attachment;
filename=setup.xml"); // also tried other file names and attachment with no
file name
  ServletOutputStream out = response.getOutputStream();
  String exportFile = <generate file contents as a string here>
  response.setContentLength(exportFile.length());
  out.write(exportFile.getBytes());
  out.flush();
  out.close();

This downloads the file properly, but on IE 6.x it corrupts the DOM Document
on the browser.  The form is submitted from JavaScript and all of the
buttons on the form invoke JavaScript functions.  After downloading the file
on IE 6.x, any attempt by JavaScript to reference the "document" object
causes an "Unspecified Error".  Inspecting the JavaScript environment with a
script debugger shows that "document" is no longer an object.

I can't find anyone else having this problem, and I've tried many different
ways to solve it.  If anyone has experience with this, please let me know
what you did.

Thanks,
Eric Hodges


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Question about downloading files from a Struts servlet

Posted by Daniel Perry <d....@netcase.co.uk>.
Not sure what is wrong, but for a possible work-around, have you tried
making the target for the form (or link) a new window?

Daniel.


> -----Original Message-----
> From: Eric Hodges [mailto:EHodges@USDataworks.com]
> Sent: 27 August 2004 17:17
> To: Struts Users Mailing List (E-mail)
> Subject: Question about downloading files from a Struts servlet
>
>
> I have a Struts form and action that downloads a file to the client.  The
> servlet code looks like this:
>
>   response.reset();
>   AdminSetupForm setupForm = (AdminSetupForm) form;
>   response.setContentType("application/download");  // also tried
> "application/octet-stream", "junk/xml", etc.
>   response.addHeader("Content-disposition", "attachment;
> filename=setup.xml"); // also tried other file names and
> attachment with no
> file name
>   ServletOutputStream out = response.getOutputStream();
>   String exportFile = <generate file contents as a string here>
>   response.setContentLength(exportFile.length());
>   out.write(exportFile.getBytes());
>   out.flush();
>   out.close();
>
> This downloads the file properly, but on IE 6.x it corrupts the
> DOM Document
> on the browser.  The form is submitted from JavaScript and all of the
> buttons on the form invoke JavaScript functions.  After
> downloading the file
> on IE 6.x, any attempt by JavaScript to reference the "document" object
> causes an "Unspecified Error".  Inspecting the JavaScript
> environment with a
> script debugger shows that "document" is no longer an object.
>
> I can't find anyone else having this problem, and I've tried many
> different
> ways to solve it.  If anyone has experience with this, please let me know
> what you did.
>
> Thanks,
> Eric Hodges
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org