File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Upload multiple files with separate submit buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Upload multiple files with separate submit buttons" Watch "Upload multiple files with separate submit buttons" New topic

Upload multiple files with separate submit buttons

Jerome Jabson

Joined: Jan 15, 2009
Posts: 5

I am new to web development and this is my first struts application. I am developing a feature in a large application that allows for custom reporting. I am having a problem with uploading multiple files using separate "Upload" buttons. Basically, the input to generate reports can either be manually entered or the user may select to upload a comma separated file. However, the inputs are come from different textareas that are populated by the uploaded files from 3 different selections. I am using FormFile to upload the files and it works great for the first file and the textarea is populated corrected. But when when I try to upload the next file, the Action class is not able to obtain the file location. I noticed in debug mode that the all the file attributes are either empty ("") or null.

Here's what I have defined in my JSP:

(btw - I have tried using <html:file> and I am getting the same results)

Here's what I have configured in the struts.xml file:

Here is what I have in my ActionForm:

My Action class is fairly large so I'll just add the code that handles the file upload:

There is something that maybe a clue as to why this is not working, however, I was not able to find any reference on this anywhere. I noticed that during debug that the file object contains an attribute: FieldName. FieldName contains the value: "theFile". Notice that the property name for the first tag in my file is "theFile". It seems to me - and I'm just guessing here - that struts only allows for a single file upload in a session. Is there something I need to do that allows for what I am trying to do? I would appreciate any help in this matter or some pointers that would some an example for how this can be done.

Jerome Jabson

Joined: Jan 15, 2009
Posts: 5
Sorry Everyone,

I figured out the problem! My mistake in the Action class.

Sorry for the any inconvenience.

I agree. Here's the link:
subject: Upload multiple files with separate submit buttons
Similar Threads
Display Tag Library auto-paging problem
File Upload
Why File name is becoming null in action class ?
Map the action form object
Displaying file content in a jsp page