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, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to