• 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 Download a file

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I like to know how can i download a file using struts. When i forwarding the action mapping class to a file in the server it is get displayed. I don't think this will not be secure. Please let me have some code sample.

Thanks & Regards

Mohammed
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a small number of files a user can downlad, putting the files in the web context and having an action forward to them is not a bad option. If you're concerned about a user guessing the file location and downloading them without going through your action, you can always put them in the WEB-INF directory. That way even if a user does guess the location, they still can't download the file directly.

If you have a larger collection of files, or have files that are dynamically generated, you will need to use the java.io package to read the file and then output it to the HttpServletResponse object's Output Stream. There is a Struts Action that you can subclass that will help you do this. Look for DownloadAction in the struts extras javadoc.
reply
    Bookmark Topic Watch Topic
  • New Topic