• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Certainly. Just change the file type to "application/vnd.ms-excel".
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please give an example on the download file without extending the DownloadAction class?

Thanks
Jaydeep
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic