Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

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

Raghuveer Vellanki

2007-02-27

Replies:

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@(protected)]
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@(protected):
>
> 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@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.