I'm having a problem uploading a file using spring webflow 1.0 and struts 1.3.

The jsp is something like this:

<html:form action="/flowAction" method="post" enctype="multipart/form-data">
    <!-- snip -->
    <html:file property="file" name="attachDocumentsForm" size="50"/>
    <!-- snip -->

The Form is something like this:

public class AttachDocumentsForm extends SpringBindingActionForm {
    // note, SpringBindingActionForm extends struts' ActionForm
    private FormFile file;

Now, my problem is that when I submit the form, the file field is always null. The other fields on the form are filled out properly, and if I dig through the RequestContext, I can find the file is buried deep some of the data structures there.

Here is the horribly ugly way that I can get at the attachment:

// 'context' is the RequestContext
ServletExternalContext servletExternalContext = (ServletExternalContext) context.getExternalContext();
ActionForm form = (ActionForm) servletExternalContext.getRequest().getAttribute("actionForm");
FormFile file = (FormFile) form.getMultipartRequestHandler().getFileElements().get("file");

I've noticed that the MultipartRequestHandler on my form is null, and I suspect that this might be part of the problem, but I've tried populating it with an instance of CommonsMultipartRequestHandler to no avail.

What do I need to do to let the file field be populated correctly?


Add a field called file of type FormFile in your ActionForm (the one refered by "attachDocumentsForm"), along with the accessor methods.

THe uploaded file can be accessed by calling form.getFile().

I hope this helps!

Thanks, but that's just the problem. I already have one of those fields on the ActionForm, but it is always null.
I don't know if anyone came through this since 2006, but I have the exact same problem in a legacy project I'm working on... if someone has the solution, that'd be great :-)
+1  A: 

I think you should configure spring dispatcher servlet:

Thanks for the update, I will look into this. I know that I consulted the docs you linked, and defined a multipart resolver as part of that process. I am not at all sure that I had it wired up correctly though (it's been a few months since I looked at this). I'll take another pass at it when I get a chance.