struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Raghu" <raghuve...@infotechsw.com>
Subject RE: How to make the file to download when clicking on a link --use DownloadAction in struts 1.2.8
Date Tue, 27 Feb 2007 14:55:32 GMT
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 <satish@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


Mime
View raw message