File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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

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


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 "", 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
Will try that
Sean Sullivan
Ranch Hand

Joined: Sep 09, 2001
Posts: 427

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


George Franciscus
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

George Franciscus<br /><br /><a href="" target="_blank" rel="nofollow"></a><br /><a href="" target="_blank" rel="nofollow"></a>
vicky malhotra

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.


I agree. Here's the link:
subject: Using Struts to save files
It's not a secret anymore!