struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hill" <andrew.david.h...@gridnode.com>
Subject RE: Newbie Q: Missing parameters with multipart/form-data
Date Fri, 13 Jun 2003 10:23:57 GMT
<snip>
specifically Actions but not Forms
</snip>

Ahh... which is of course why there are no request parameters... (Assuming
1.0.2 populates its multipart forms the same way!) Ive not actually played
with 1.0.2 so I dont know the intricate details, but I can tell you that it
is a little bit different in the way it processes requests.

Struts 1.1 Uses a thing called a RequestProcessor which the ActionServlet
delegates to in order to do the heavy lifting. In 1.0.2 its all done in the
ActionServlet. That said it probably does much the same stuff - though you
would want to check the source code to confirm this.

Assuming 1.0.2 also required an ActionForm in order to process its multipart
forms then your quickest solution might be to create a dummy actionform to
use with that action. While it wouldnt have any properties its existence
should invoke the population of the MultipartRequestWrapper. BUT if your not
using ActionForms then how are you getting at the uploaded files? Are you
parsing the request yourself - in this case if you let struts do it it will
have already read from the requests InputStream by the time it gets to you
which may be problematic...

I think file upload is one of those things that has changed a fair bit in
1.1 so you will want to scan the source to see just what its doing (btw:
back in 1.0.2 it was a part of struts and was factored out into the seperate
commons project later so that other apps could use it alone if they wanted
too).

<snip>
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?
</snip>

Umm. You might need to change some stuff - but from what Ive heard on the
list its not difficult to upgrade - but if your comfortable with 1.0.2 you
might just want to stick to it for now. Id search the archives on that as I
think it gets asked a fair bit.

<snip>
 Oh and I suppose most importantly is the new version stable?
</snip>

Well its up to RC2 status now. Id wager its more stable than 1.0.2 - but you
can always check the bugzilla to see what defects are left outstanding.
http://issues.apache.org/bugzilla/






-----Original Message-----
From: Chris Cooper [mailto:ChrisCooperStrutsList@hotmail.com]
Sent: Friday, 13 June 2003 18:01
To: Struts Users Mailing List; andrew.david.hill@gridnode.com
Subject: Re: Newbie Q: Missing parameters with multipart/form-data


Andrew,

Thanks for responding, answers are as follows:

> I havent really grokked what it is your doing here, but can share an
insight
> 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
servlet
> api only include those values that are part of the request uri - form
fields
> are not included. Obviously this makes life a little difficult so struts
(or
> rather the commons file-upload) kindly parses the request to extract the
> field values (and files) from whatever elwierdo format the browser
submitted
> 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 -
which
> 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,
and
> 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. (upload.do?folderId=n)
> </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
(upload.do?folderId=n), 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
are
> 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) :)

Cheers,

Chris.

> -----Original Message-----
> From: Chris Cooper [mailto:ChrisCooperStrutsList@hotmail.com]
> 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
still
> > 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
the
> > page with the form, the URL for this form has a URL encoded parameter
for
> a
> > target folderId in my database.  This folderId parameter is added as a
> > hidden input in the form on the generated page. (upload.do?folderId=n)
> >
> > 2. The user selects a number of files to upload using:
> >
> > <form name="upload" action="upload.do" 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 upload.do (my users may want to
upload
> > more files), the folderId is again added as a hidden input into the
form,
> > 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
the
> > request.
> >
> > 6. Step 2 happens again. Parameter folderId is *definitely* still there
in
> > 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
2.1Mb
> 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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message