You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by an...@world2web.com on 2005/08/21 13:48:03 UTC

Struts Download Action

Hi All,

I'm developing a web application based on Struts. In this, one of the
features to be included is , to download a file, when the user clicks on
the link in the JSP page.

Also, when the user clicks on the link, the Save/Open dialog box should
appear.

If nyone has used the DownloadAction provided by Struts OR any other
solution , please help.

Thanks




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


Re: Struts Download Action

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Thanks Martin, that's precisely the page I was referring to.  I couldn't 
get out to it a few minutes ago... looks like my network hiccuped 
momentarily.

Frank

Martin Gainty wrote:
> Frank et al
> 
> This may be useful for your  development effort
> http://wiki.apache.org/struts/StrutsFileDownload
> 
> Martin-
> 
> ----- Original Message ----- From: "Frank W. Zammetti" 
> <fz...@omnytex.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Sunday, August 21, 2005 10:08 AM
> Subject: Re: Struts Download Action
> 
> 
>> I can't seem to access the Wiki right now to give you an exact link, 
>> but if you search for DownloadAction there, you will find a page that 
>> includes a sample app I wrote to demonstrate using the action.  It 
>> shows downloading a file on the file system and also from a database, 
>> if that is relevant for your use case.  The page gives a good overview 
>> of using it besides.
>>
>> I have used this action myself, and well as a straight servlet 
>> approach... I'm not sure either is better than the other, or easier, 
>> but I would go with the DownloadAction since your app is already 
>> Struts-based just to "keep it all in one place".
>>
>> Frank
>>
>> anuradhasa@world2web.com wrote:
>>
>>> Hi All,
>>>
>>> I'm developing a web application based on Struts. In this, one of the
>>> features to be included is , to download a file, when the user clicks on
>>> the link in the JSP page.
>>>
>>> Also, when the user clicks on the link, the Save/Open dialog box should
>>> appear.
>>>
>>> If nyone has used the DownloadAction provided by Struts OR any other
>>> solution , please help.
>>>
>>> Thanks
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>>
>>> .
>>>
>>
>> -- 
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


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


Re: Struts Download Action

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I can't seem to access the Wiki right now to give you an exact link, but 
if you search for DownloadAction there, you will find a page that 
includes a sample app I wrote to demonstrate using the action.  It shows 
downloading a file on the file system and also from a database, if that 
is relevant for your use case.  The page gives a good overview of using 
it besides.

I have used this action myself, and well as a straight servlet 
approach... I'm not sure either is better than the other, or easier, but 
I would go with the DownloadAction since your app is already 
Struts-based just to "keep it all in one place".

Frank

anuradhasa@world2web.com wrote:
> Hi All,
> 
> I'm developing a web application based on Struts. In this, one of the
> features to be included is , to download a file, when the user clicks on
> the link in the JSP page.
> 
> Also, when the user clicks on the link, the Save/Open dialog box should
> appear.
> 
> If nyone has used the DownloadAction provided by Struts OR any other
> solution , please help.
> 
> Thanks
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 
> .
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


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


Re: Struts Download Action

Posted by Larry Meadors <la...@gmail.com>.
I have used a straight servlet to download a blob from a database
using a URL like this:

http://someserver/documents/123/file.pdf

I did it this way instead of using struts because IE is a pile of crap. :-)

In this URL, the /123/ is the record's id, and file.pdf is the
suggested extension for the browser, which just thinks that is it a
static file.

If you're interested, I can send you the source for the servlet - it's
only a few lines of code.

Larry


On 8/21/05, anuradhasa@world2web.com <an...@world2web.com> wrote:
> Hi All,
> 
> I'm developing a web application based on Struts. In this, one of the
> features to be included is , to download a file, when the user clicks on
> the link in the JSP page.
> 
> Also, when the user clicks on the link, the Save/Open dialog box should
> appear.
> 
> If nyone has used the DownloadAction provided by Struts OR any other
> solution , please help.
> 
> Thanks
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Struts Download Action

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
It actually does say right at the top that it was added in 1.2.6.  If 
you think that should be expanded upon, feel perfectly free to add to 
the page... that's the beauty of a Wiki after all :)

Frank

Anuradha S.Athreya wrote:
> Thanks , I got it working with Download Action. But one thing missing in the
> tutorial was that there was no mention that this Download Action was
> available post struts 1.2.6. Would be great if this is included.
> 
> Thanks all.
> 
> 
>  
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
> Sent: Monday, August 22, 2005 5:16 AM
> To: Struts Users Mailing List
> Subject: Re: Struts Download Action
> 
> That's good info... might be worth adding to the Wiki (hint-hint :) )
> 
> Also, I don't think there is anything to stop you from using the 
> DownloadAction in Struts prior to 1.2.6 when, IIRC, it was added.  I 
> could be wrong, but I don't remember anything that would make that not work.
> 
> Frank
> 
> Sudhaker Raj wrote:
> 
>>http://wiki.apache.org/struts/StrutsFileDownload is great, but in case
>>you are using struts older than 1.2.6...
>>
>>You just return null from execute method, framework will not do any
>>thing further. Now it is your responsibility to read the target file,
>>set correct content-type and then write the content on
>>response.getOutputStream();
>>
>>Sample code:
>>
>>public class ResponseWriterAction extends Action {
>>
>>    public ActionForward execute( ActionMapping mapping,
>>                                  ActionForm form,
>>                                  HttpServletRequest request,
>>                                  HttpServletResponse response)
>>            throws Exception {
>>
>>        response.setContentType("application/zip");
>>        // Set the content disposition
>>        // To download
>>        response.setHeader("Content-disposition", 
>>                           "attachment; filename=" + fileName);
>>        // To open up in the browser
>>        // response.setHeader("Content-disposition", 
>>        //                   "inline; filename=" + fileName);
>>
>>        byte[] buff = new byte[4096]; // 4KB
>>        
>>        OutputStream out = response.getOutputStream();
>>        while (moreContent) {
>>            // read content in buff byte[]
>>            out.write(buff);
>>        }
>>        out.close();
>>        return null;
>>  }
>>}
>>
>>Hope this helps.
>>
>>Cheers,
>>Sudhaker
>>
>>On 8/21/05, anuradhasa@world2web.com <an...@world2web.com> wrote:
>>
>>
>>>Hi All,
>>>
>>>I'm developing a web application based on Struts. In this, one of the
>>>features to be included is , to download a file, when the user clicks on
>>>the link in the JSP page.
>>>
>>>Also, when the user clicks on the link, the Save/Open dialog box should
>>>appear.
>>>
>>>If nyone has used the DownloadAction provided by Struts OR any other
>>>solution , please help.
>>>
>>>Thanks
>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>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
>>
>>
>>
>>
>>
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


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


RE: Struts Download Action

Posted by "Anuradha S.Athreya" <an...@world2web.com>.
Thanks , I got it working with Download Action. But one thing missing in the
tutorial was that there was no mention that this Download Action was
available post struts 1.2.6. Would be great if this is included.

Thanks all.


 
-----Original Message-----
From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
Sent: Monday, August 22, 2005 5:16 AM
To: Struts Users Mailing List
Subject: Re: Struts Download Action

That's good info... might be worth adding to the Wiki (hint-hint :) )

Also, I don't think there is anything to stop you from using the 
DownloadAction in Struts prior to 1.2.6 when, IIRC, it was added.  I 
could be wrong, but I don't remember anything that would make that not work.

Frank

Sudhaker Raj wrote:
> http://wiki.apache.org/struts/StrutsFileDownload is great, but in case
> you are using struts older than 1.2.6...
> 
> You just return null from execute method, framework will not do any
> thing further. Now it is your responsibility to read the target file,
> set correct content-type and then write the content on
> response.getOutputStream();
> 
> Sample code:
> 
> public class ResponseWriterAction extends Action {
> 
>     public ActionForward execute( ActionMapping mapping,
>                                   ActionForm form,
>                                   HttpServletRequest request,
>                                   HttpServletResponse response)
>             throws Exception {
> 
>         response.setContentType("application/zip");
>         // Set the content disposition
>         // To download
>         response.setHeader("Content-disposition", 
>                            "attachment; filename=" + fileName);
>         // To open up in the browser
>         // response.setHeader("Content-disposition", 
>         //                   "inline; filename=" + fileName);
> 
>         byte[] buff = new byte[4096]; // 4KB
>         
>         OutputStream out = response.getOutputStream();
>         while (moreContent) {
>             // read content in buff byte[]
>             out.write(buff);
>         }
>         out.close();
>         return null;
>   }
> }
> 
> Hope this helps.
> 
> Cheers,
> Sudhaker
> 
> On 8/21/05, anuradhasa@world2web.com <an...@world2web.com> wrote:
> 
>>Hi All,
>>
>>I'm developing a web application based on Struts. In this, one of the
>>features to be included is , to download a file, when the user clicks on
>>the link in the JSP page.
>>
>>Also, when the user clicks on the link, the Save/Open dialog box should
>>appear.
>>
>>If nyone has used the DownloadAction provided by Struts OR any other
>>solution , please help.
>>
>>Thanks
>>
>>
>>
>>
>>---------------------------------------------------------------------
>>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
> 
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


---------------------------------------------------------------------
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


Re: Struts Download Action

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
That's good info... might be worth adding to the Wiki (hint-hint :) )

Also, I don't think there is anything to stop you from using the 
DownloadAction in Struts prior to 1.2.6 when, IIRC, it was added.  I 
could be wrong, but I don't remember anything that would make that not work.

Frank

Sudhaker Raj wrote:
> http://wiki.apache.org/struts/StrutsFileDownload is great, but in case
> you are using struts older than 1.2.6...
> 
> You just return null from execute method, framework will not do any
> thing further. Now it is your responsibility to read the target file,
> set correct content-type and then write the content on
> response.getOutputStream();
> 
> Sample code:
> 
> public class ResponseWriterAction extends Action {
> 
>     public ActionForward execute( ActionMapping mapping,
>                                   ActionForm form,
>                                   HttpServletRequest request,
>                                   HttpServletResponse response)
>             throws Exception {
> 
>         response.setContentType("application/zip");
>         // Set the content disposition
>         // To download
>         response.setHeader("Content-disposition", 
>                            "attachment; filename=" + fileName);
>         // To open up in the browser
>         // response.setHeader("Content-disposition", 
>         //                   "inline; filename=" + fileName);
> 
>         byte[] buff = new byte[4096]; // 4KB
>         
>         OutputStream out = response.getOutputStream();
>         while (moreContent) {
>             // read content in buff byte[]
>             out.write(buff);
>         }
>         out.close();
>         return null;
>   }
> }
> 
> Hope this helps.
> 
> Cheers,
> Sudhaker
> 
> On 8/21/05, anuradhasa@world2web.com <an...@world2web.com> wrote:
> 
>>Hi All,
>>
>>I'm developing a web application based on Struts. In this, one of the
>>features to be included is , to download a file, when the user clicks on
>>the link in the JSP page.
>>
>>Also, when the user clicks on the link, the Save/Open dialog box should
>>appear.
>>
>>If nyone has used the DownloadAction provided by Struts OR any other
>>solution , please help.
>>
>>Thanks
>>
>>
>>
>>
>>---------------------------------------------------------------------
>>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
> 
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


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


Re: Struts Download Action

Posted by Sudhaker Raj <su...@gmail.com>.
http://wiki.apache.org/struts/StrutsFileDownload is great, but in case
you are using struts older than 1.2.6...

You just return null from execute method, framework will not do any
thing further. Now it is your responsibility to read the target file,
set correct content-type and then write the content on
response.getOutputStream();

Sample code:

public class ResponseWriterAction extends Action {

    public ActionForward execute( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response)
            throws Exception {

        response.setContentType("application/zip");
        // Set the content disposition
        // To download
        response.setHeader("Content-disposition", 
                           "attachment; filename=" + fileName);
        // To open up in the browser
        // response.setHeader("Content-disposition", 
        //                   "inline; filename=" + fileName);

        byte[] buff = new byte[4096]; // 4KB
        
        OutputStream out = response.getOutputStream();
        while (moreContent) {
            // read content in buff byte[]
            out.write(buff);
        }
        out.close();
        return null;
  }
}

Hope this helps.

Cheers,
Sudhaker

On 8/21/05, anuradhasa@world2web.com <an...@world2web.com> wrote:
> Hi All,
> 
> I'm developing a web application based on Struts. In this, one of the
> features to be included is , to download a file, when the user clicks on
> the link in the JSP page.
> 
> Also, when the user clicks on the link, the Save/Open dialog box should
> appear.
> 
> If nyone has used the DownloadAction provided by Struts OR any other
> solution , please help.
> 
> Thanks
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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