File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Using Struts to save files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using Struts to save files" Watch "Using Struts to save files" New topic
Author

Using Struts to save files

Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
Thanks
Will try that
Sean Sullivan
Ranch Hand

Joined: Sep 09, 2001
Posts: 427
Karthik,

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

http://strutsblobapp.sourceforge.net/

Cheers,

-Sean
George Franciscus
author
Ranch Hand

Joined: Jan 25, 2005
Posts: 32
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


George Franciscus<br />george.franciscus@nexcel.ca<br /><a href="http://www.nexcel.ca" target="_blank" rel="nofollow">http://www.nexcel.ca</a><br /><a href="http://www.manning.com/franciscus" target="_blank" rel="nofollow">http://www.manning.com/franciscus</a>
vicky malhotra
Greenhorn

Joined: Feb 05, 2005
Posts: 16
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Struts to save files