You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Kennedy <da...@dksy.net> on 2006/09/11 09:22:52 UTC

Download file from server and save on client

I need to download a file from a server to client computer using Struts.
I've implemented StrutsFileDownload from the Struts Wiki, but this displays
the contents of the file 
http://wiki.apache.org/struts/StrutsFileDownload


How can I save the file on the client drive instead of displaying the
contents?



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


Re: Download file from server and save on client

Posted by Thomas Joseph <th...@kottsoftware.com>.
Hi Dave,

Basically you have to set the content disposotion to "attachment"  
eg..

     //setting the content type to an arbitrary one, so to make browsers 
     //definitely download the file. Some browsers simply ignore download 
     //instruction and display the content once they know its content-type to
     //be something displayable.
     response.setContentType("application/x-download");
     response.setHeader("Content-Disposition", "attachment; filename=" + filename);

See here:

http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index3.html

Thanks and Regards,
Thomas Joseph 

Kott Software Pvt. Ltd. | Vallamattom Estate | M.G.Road | Cochin-682015 | India 
www.kottsoftware.com 
--------------------------------------------------------------------------------
This email (including any attachments) is subject to copyright, the information in it is confidential, and it is legally privileged. Use of this email or of any information in it other than by the addressee is unauthorized and unlawful. If you are not the intended recipient of the mail, kindly notify the author of the mail and delete the same. 
--------------------------------------------------------------------------------
It doesn't matter how you were, but rather how you are that decides your future. A right attitude will get you to Success. 
  ----- Original Message ----- 
  From: Dave Kennedy 
  To: user@struts.apache.org 
  Sent: Monday, September 11, 2006 12:52 PM
  Subject: Download file from server and save on client


  I need to download a file from a server to client computer using Struts.
  I've implemented StrutsFileDownload from the Struts Wiki, but this displays
  the contents of the file 
  http://wiki.apache.org/struts/StrutsFileDownload


  How can I save the file on the client drive instead of displaying the
  contents?



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


Re: Download file from server and save on client

Posted by Hassan Schroeder <ha...@gmail.com>.
On 9/11/06, Dave Kennedy <da...@dksy.net> wrote:
> I need to download a file from a server to client computer using Struts.
> I've implemented StrutsFileDownload from the Struts Wiki, but this displays
> the contents of the file
> http://wiki.apache.org/struts/StrutsFileDownload

The answer is in the "Content Disposition" section of the above page...

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

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


Re: Download file from server and save on client

Posted by Martin Gainty <mg...@hotmail.com>.
Mr Kennedy

Did you get a chance to look at ServletOutputStreamWrapper class?
 http://struts.apache.org/2.x/struts2-core/apidocs/index.html

Here is a q&d example that uses it
http://rifers.org:8088/browse/~raw,r=3183/rifers/jhighlight/trunk/src/com/uwyn/jhighlight/servlet/HighlightFilter.java

Anyone else?
Martin--
*********************************************************************
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.



----- Original Message ----- 
From: "Dave Kennedy" <da...@dksy.net>
To: <us...@struts.apache.org>
Sent: Monday, September 11, 2006 3:22 AM
Subject: Download file from server and save on client


>I need to download a file from a server to client computer using Struts.
> I've implemented StrutsFileDownload from the Struts Wiki, but this displays
> the contents of the file 
> http://wiki.apache.org/struts/StrutsFileDownload
> 
> 
> How can I save the file on the client drive instead of displaying the
> contents?
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>