• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Struts to save files

 
Karthik Krishnamurthy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a file manager software using struts. I have written the code to upload the file easily using the html:file tag.
However when the user has to see the files that have been uploaded, I need to give him the ability to save the uploaded file (name displayed as a link) to disk.
How do i do that.
Thanks Karthik
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karthik,

First of all, I have to ask you to change your display name to comply with our naming policy -- we require people to use real, or at least real-looking names.

Thanks.

As to your question about downloading the files, the general approach is to have a Servlet (Struts Action class in your case) proxy the filesystem for the client. For example, if your upload stores the uploaded files under "/var/data", you'd want your DownloadAction to serve a request to, say "DownloadAction.do?file=sample.txt", by streaming the file "/var/data/sample.txt" to the web browser.
 
Karthik Krishnamurthy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
Will try that
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik,

I wrote a Struts application that demonstrates File Upload and File Download:

http://strutsblobapp.sourceforge.net/

Cheers,

-Sean
 
George Franciscus
author
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There seems to be a lot of questions about file upload/download.

Have a look at Struts Recipes, recipe 2.9

Chapter 2 is available at http://www.manning-source.com/books/franciscus/franciscus_chp2.pdf
 
vicky malhotra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kartik,

I went through the code of your applicationa and i have a doubt. In the "fileList.jsp", there is this logic:iterate tag:

<logic:iterate id="file" name="files">

What does this "files" refer to? there is no such field in the form associated with this JSP. Please clarify the same.

Regards,

Vicky
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic