struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Cooper" <>
Subject Re: Newbie Q: Missing parameters with multipart/form-data
Date Fri, 13 Jun 2003 10:01:13 GMT

Thanks for responding, answers are as follows:

> I havent really grokked what it is your doing here, but can share an
> into multipart forms using struts that you probably already know and
> probably wont help you - but maybe you can relate it to your situation?

I'm basically producing a page with a form to upload 8 files at a time for
processing and upload into a DB.  The user navigates to a target folder
(with a folderId) in a previous page, and is then forwarded to this page.
After each upload (of one or more files) takes place, the user is forwarded
back to the same page to upload more files.  Essentially I'm writing a bulk
upload facility into an existing struts app.

> HttpServletRequest parameters for multipart forms as provided by the
> api only include those values that are part of the request uri - form
> are not included. Obviously this makes life a little difficult so struts
> rather the commons file-upload) kindly parses the request to extract the
> field values (and files) from whatever elwierdo format the browser
> them in and uses them to populate an object that 'wraps' the original
> request. This populating is done just prior to the actionform being
> populated (and only occurs if you have an action form!).

Thanks that clarified a few queries I had about the sequence of events.

> The wrapper is available throughout your action, however when you forward
> from the action is is 'unwrapped' so forwarding is done using the original
> request object (theres a bug in some 1.1 versions prior to b3 where this
> didnt happen) as some containers dont like to forward on the wrapper -
> doesnt extend HttpServletRequestWrapper in order to stay compatible with
> servlet api 2.2

The version of struts we are using is 1.0.2, which is the latest stable
release as far as I know, we have not upgraded here to the latest beta.
Although I'm not sure if that is inertia or for a reason.  It is however
interesting to know that there is a related bug that has been fixed.  Is is
possible to just swap the jar for the old version with the new?  Or are
there interface changes and/or deprecations that would have to be taken into
account?  Oh and I suppose most importantly is the new version stable? :)

> Now in your case, as far as I can see from what you are saying, you are
> repeating the *same* process 3 times, and the first two times it works,
> the third fails. What is different the third time? Can you explain the
> problem better?

The first time the page is generated from a GET, the second is the result of
the first POST and the third is the result of the second POST, as far as I
can tell the HTML generated from the GET and both POSTs are identical.  The
session is the same as is everything else apart from the files beiong
uploaded, which as I mentioned earlier are 500K, 1M and 2.1M in size.  I
don't think the file size is the problem as I have sucessfully uploaded
files of 70 to 80Mb.

> I can easily imagine something failing on the first or second try, but the
> third... strange!

Tell me about it! :)

> <snip>
> This folderId parameter is added as a hidden input in the form on the
> generated page. (
> </snip>
> The "?folder=n" in the url is a url parameter thinghy not a hidden input -
> so that statement seems a bit contradictory. Which is it you are using. As
> explained above the difference can be significant for a multipart form.

Yeah on re-reading that does look a little confusing, what I meant was:
The initial request is in the guise of a URL encoded parameter
(, the HTML that is generated has the form with the
hidden input (<input type="hidden" name="folderId" value="n"/>)

> Since the aim is to upload multiple files (one at a time?) I presume you
> using a session scoped action form?

Unfortunately, a decision was made (long before I started working here) to
only use part of Struts, specifically Actions but not Forms (NO I HAVE NO
IDEA WHY!) so session scoped action forms are not being used.  The JSP uses
a number of taglibs to generate XML, with the outer-most taglib used to
apply XSLT to the resultant XML to generate HTML.  It would appear that
anything less than 4 levels of inderection here is regarded with derrision
and distain. (Or event the work of children) :)



> -----Original Message-----
> From: Chris Cooper []
> Sent: Friday, 13 June 2003 16:54
> To: Struts Users Mailing List
> Subject: Re: Newbie Q: Missing parameters with multipart/form-data
> No takers?
> > Hi guys,
> >
> > I've had a good look through the archives (and in fact pretty much the
> whole
> > of Usenet!) and I find several mentions of my problem similar to my own,
> but
> > no solutions.
> >
> > Please bear with me and read "parameter" as "parameter/attribute", I
> > haven't quite got the distinction concrete in my mind as yet!
> >
> > The problem is as follows:
> >
> > 1. I have a form for uploading multiple files, initially the user GETs
> > page with the form, the URL for this form has a URL encoded parameter
> a
> > target folderId in my database.  This folderId parameter is added as a
> > hidden input in the form on the generated page. (
> >
> > 2. The user selects a number of files to upload using:
> >
> > <form name="upload" action="" encoding="multipart/form-data">
> >     <input type="file" name="uploadFile_n">
> >     etc...
> >     <input type="hidden" name="folderId" value="n"/>
> >     Submit...
> > </form>
> >
> > The user then hits the upload button to POST the form.
> >
> > 3. The UploadAction receives the POST request, processes each file and
> sets
> > the ForwardAction to the same page (my users may want to
> > more files), the folderId is again added as a hidden input into the
> > and the URL encoded parameter is now gone.
> >
> > 4. Step 2 happens again. Parameter folderId is still there in the form.
> >
> > 5. Step 3 happens again. Parameter folderId is still there attached to
> > request.
> >
> > 6. Step 2 happens again. Parameter folderId is *definitely* still there
> > the form, I have checked the HTML source!
> >
> > 7. Step 3 loses the plot, the getParameter("folderId") and
> > getAttribute("folderId") both return null!  The parameter is no longer
> > attached to the request nor are any of the file parameters present.
> However
> > the usual struts attributes are attached as expected.
> >
> > The form is very definitely being POSTed and the form definitely has the
> > hidden input and the file inputs present, but at some point before my
> > Action's performActionOnMultipartForm () method is being called, the
> > parameters disappear into the Ether...
> >
> > I have reproduced this problem consistently, on reach occasion i upload
> the
> > same files (one each time) all three are JPEG images 500Kb, 1Mb and
> in
> > size respectively, is the file size a problem?
> >
> > Frankly I am very confused, and would really appreciate any light that
> > anyone can show on this, a solution would earn my undying gratitude :)
> >
> > Regards,
> >
> > Chris Cooper

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message