You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Balwinder <ba...@saigun.com> on 2006/11/03 17:04:14 UTC

Downloading file

Hi All,

I am developing an application in struts in which I needed to download a 
file from a server.  When iam clicking on download button, file lose its 
extension and it with the action ie .do and does not open with the 
associated application.

Any help is highly appreciated.

Thanks in advance.

Thanks and Regards,
Balwinder Kumar

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


Re: Downloading file

Posted by Niall Pemberton <ni...@gmail.com>.
On 11/3/06, Balwinder <ba...@saigun.com> wrote:
> Hi All,
>
> I am developing an application in struts in which I needed to download a
> file from a server.  When iam clicking on download button, file lose its
> extension and it with the action ie .do and does not open with the
> associated application.
>
> Any help is highly appreciated.

Should be a case of setting the content type and disposition properly:

For example, for a pdf file:
        response.setContentType("application/pdf");

Then, if you want it to open in the browser, with assoc application:
        response.setHeader("Content-disposition", "inline; filename="
+ fileName);

If you want to save it to disk
        response.setHeader("Content-disposition", "attachment;
filename=" + fileName);

>From memory I also had to play with the headers that say "don't cache"

Niall

> Thanks in advance.
>
> Thanks and Regards,
> Balwinder Kumar

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


Re: Downloading file

Posted by Balwinder <ba...@saigun.com>.
Mike Baroukh wrote:

>
> You must use content-disposition header :
>
> response.setHeader("Content-Disposition", "attachment; 
> filename=\""+myfilename+"\"");
>
> You can also add a mime type with something like
>
> String mimeType = getServletContext().getMimeType(myfilename);
> response.setHeader("Content-Type", 
> mimeType==null?"x-type/unknown":mimeType);
>
>
>
>
> Mike
>
> Balwinder a écrit :
>
>> Hi All,
>>
>> I am developing an application in struts in which I needed to 
>> download a file from a server.  When iam clicking on download button, 
>> file lose its extension and it with the action ie .do and does not 
>> open with the associated application.
>>
>> Any help is highly appreciated.
>>
>> Thanks in advance.
>>
>> Thanks and Regards,
>> Balwinder Kumar
>>
>> ---------------------------------------------------------------------
>> 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
>
Thanks a lot!!Iam through this  problem, it is working now.

Thanks and Regards,
Balwinder Kumar

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


Re: Downloading file

Posted by Mike Baroukh <mb...@cardiweb.com>.
You must use content-disposition header :

response.setHeader("Content-Disposition", "attachment; 
filename=\""+myfilename+"\"");

You can also add a mime type with something like

String mimeType = getServletContext().getMimeType(myfilename);
response.setHeader("Content-Type", 
mimeType==null?"x-type/unknown":mimeType);




Mike

Balwinder a écrit :
> Hi All,
>
> I am developing an application in struts in which I needed to download 
> a file from a server.  When iam clicking on download button, file lose 
> its extension and it with the action ie .do and does not open with the 
> associated application.
>
> Any help is highly appreciated.
>
> Thanks in advance.
>
> Thanks and Regards,
> Balwinder Kumar
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


-- 

Mike Baroukh

---
Cardiweb  - 31 Rue de Mogador Paris IXeme
06 63 57 27 22 - 01 53 21 82 63 - Jabber: mbaroukh@jabber.org
http://www.cardiweb.com
---



Re: Downloading file

Posted by Puneet Lakhina <pu...@gmail.com>.
On 11/3/06, Balwinder <ba...@saigun.com> wrote:
>
> Hi All,
>
> I am developing an application in struts in which I needed to download a
> file from a server.  When iam clicking on download button, file lose its
> extension and it with the action ie .do and does not open with the
> associated application.
>
> Any help is highly appreciated.


You need to do something like this.
response.setHeader ("Content-Disposition", "attachment;filename=foo.pdf");

where foo.pdf is the file name you want to be displayed to the
user.Imassuming since the file is being served you are correctly
setting the the
content type of your response.

Thanks in advance.
>
> Thanks and Regards,
> Balwinder Kumar
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Puneet