struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Cooper" <mart...@apache.org>
Subject Re: multipart-request / file upload problem
Date Mon, 01 Mar 2004 19:23:13 GMT

"Adam Hardy" <ahardy.struts@cyberspaceroad.com> wrote in message
news:40431F81.6090601@cyberspaceroad.com...
> I'm going to put this another way: what's the secret with file upload
> requests? I can't see my file parameter in the request parameters when I
> submit the form with the multipart-request.

Ah, if I told you that, it wouldn't be a secret any more, now would it? ;-)

The biggest difference with multipart requests is that the request is
wrapped by Struts, so when you invoke a method on the request object, you
are actually invoking a method on the MultipartRequestWrapper class. This is
necessary so that calls to, for example, getParameter() go to Struts, which
parsed your request, rather than the container, which didn't.

In the code fragment below, I see you are invoking getParameterMap(). Note
that this is a Servlet 2.3 method. Since Struts 1.x is built for Servlet
2.2, that method is not implemented, and simply returns null.

Actually, there isn't a way to get the file items from the request itself,
since it doesn't have them. They're stored in the multipart request handler
itself. So, you would get the set of uploaded file items like this:

    Hashtable fileItems =
formBean.getMultipartRequestHandler().getFileElements();

I'll be the first to admit that the current multipart implementation is a
little, um, arcane (not that I invented it ;). The plan is to completely
rewrite it for Struts 2.x, when we get there.

Hope this helps.

--
Martin Cooper


>
> Adam
>
> On 02/29/2004 07:05 PM Adam Hardy wrote:
> > I use the Commons multipart request handler stuff to set up a
> > DynaActionForm properly for my file upload so:
> >
> > <form-bean  name="linklibImportForm"
> >   type="org.apache.struts.validator.DynaValidatorActionForm">
> >   <form-property name="bookmarksFile"
> >
type="org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFil
e"/>
> >
> > </form-bean>
> >
> > which works fine, but in some circumstances I want to manually create
> > this form, grab the file and save the DynaActionForm (in a filter). Like
> > so:
> >
> > ActionForm form =
> >   RequestUtils.createActionForm(request, actionMapping,
> >   moduleConfig, actionServlet);
> > form.reset(actionMapping, request);
> > BeanUtils.populate(form, request.getParameterMap());
> >
> > But it isn't working. My file comes back as null. Anyone know why or
> > have a solution?
> >
>
>
> -- 
> struts 1.1 + tomcat 5.0.16 + java 1.4.2
> Linux 2.4.20 Debian




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