Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic