You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Raghu <ra...@infotechsw.com> on 2007/02/27 15:55:32 UTC

RE: How to make the file to download when clicking on a link --use DownloadAction in struts 1.2.8

In Struts 1.2.8 we have DownloadAction  

write a class that extends extends DownloadAction 

implement folloing meyhod
---------------------------------
import org.apache.struts.actions.DownloadAction;
public class TestDownloadAction extends DownloadAction  {
  protected StreamInfo getStreamInfo(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response)
            throws FileNotFoundException,CAcsException,Exception {


 File file  = new File("c:\\test.csv");
     
        
     
        strContentType="text/csv"; // set MIME type for csv file

  return new FileStreamInfo(strContentType, file);

}//end of getStreamInfo
}//end of TestDownloadAction  class


-----Original Message-----
From: Prithivirajan Dhamodharan [mailto:prithivirajan.d@gmail.com]
Sent: Tuesday, February 27, 2007 3:56 PM
To: Struts Users Mailing List
Subject: Re: How to make the file to download when clicking on a link


follow the below steps

For HttpServletResponse set the

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

//s2-- is file
    if required set Pragma & cache-control in header.

 name
     response.setContentLength()  //file length;

Get the output  stream of HttpServleResponse ,
     bufferedoutputstream = new BufferedOutputStream(httpservletresponse
                    .getOutputStream());

Write the content and close the stream.


On 2/27/07, Satheesh <sa...@ltp.soft.net> wrote:
>
> How to make the file to download when clicking on a link using JSP...
>
> Please send me the code...
>


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