wood burning stoves 2.0*
The moose likes Struts and the fly likes How to implement download a file/pdf file in struts. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to implement download a file/pdf file in struts." Watch "How to implement download a file/pdf file in struts." New topic
Author

How to implement download a file/pdf file in struts.

kswaughs kswaughs
Greenhorn

Joined: Sep 22, 2006
Posts: 1
Hi, I am developing a struts application and one of My requirements is download a pdf file from the server when a link is clicked.

Is it possible with DownloadAction.If So please help me how to use it.
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi,
I had done the same type of functionality with an excel sheet. I believe the pdf would be more or less on the same pattern. If you require some more info, i will provide you..

I did not use DownloadAction for the above.

Regards,
Roshani


Regards,<br />Roshani
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
While you certainly don't have to use DownloadAction when writing an Action that downloads a file, using it would certainly make the process easier. You just have to override one method and Struts does the rest. Below is an example of an action that downloads the file "c:\temp\myPdfFile.pdf".



Believe it or not, that's it. The abstract DownloadAction class handles all the rest.


Merrill
Consultant, Sima Solutions
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi Merrill,

Thats really useful bit of information. Just wanted to ask you if the same may be used for Excel sheet?

Regards,
Roshani
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Certainly. Just change the file type to "application/vnd.ms-excel".
Jaydeep Deshmukh
Ranch Hand

Joined: Sep 10, 2002
Posts: 31
Can you please give an example on the download file without extending the DownloadAction class?

Thanks
Jaydeep
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Jaydeep: You can always download the Struts source code and take a look at the source for the DownloadAction class. I suspect that it is only 20 or so lines of code.

Also, if your files are saved on the web server's file system in a directory that is accessible from the outside world, you can just put a plain old link in your web page. Of course this would not work if you had to retrieve the file from a database or you wanted to wrap access to the file with some logic.

- Brent
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to implement download a file/pdf file in struts.
 
Similar Threads
File download
Using struts 1.2 how to upload a file into database and download it
Download Component functionality using servlets
how to upload and download a file in struts 2
Problem in Downloading PDF File using JSP