You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Andreas Schildbach <an...@schildbach.de> on 2005/08/28 11:34:19 UTC

Re: [FileUpload] Issue with multipart/form-data and request parameters in include

Hello Brian,

I am sorry my last answer was a bit sloppy. For the sake of simplicity, 
please consider the following JSP 2.0 fragment:

--- fragment.jsp ---
${param.p}
--- end fragment.jsp ---

This obviously outputs the parameter named p. Of course, my real 
fragment is much more complex than that, using an own controller and 
such (I was also using the words "plugin" and "portlet" because 
web-designers often use these. I was not talking about applets or 
embedded objects).

Ok, now here is a JSP which is the target of a form (I am skipping 
taglib defs):

--- target.jsp ---
<c:import url="fragment.jsp?p=value1"/>
hello world
<c:import url="fragment.jsp?p=value2"/>
--- end target.jsp ---

--- form.jsp ---
<form action="target.jsp" method="post" enctype="multipart/form-data">
   [skipping form fields]
</form>
--- end form.jsp ---

(and yes, I did get jsp:include and c:import mixed up in my last post)

Now, here is what happens with the different methods for posting the form:

1. GET: "value1 hello world value2"
2. POST (default enctype): "value1 hello world value2"
3. POST enctype="multipart/form-data": "hello world"

As I wrote, I am wondering why 2 works but I am very happy about it. It 
would be great if 3 worked as 2.

I wonder what would be a reliable way to add parameters to included 
resources, that works regardless of the type of initial request.

I am using FileUpload in a Spring (springframework.org) context, in a 
way that can be compared to a Servlet filter:

<bean id="multipartResolver" 
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

I hope I left no questions open this time. Sorry for that last 
inaccurate post.

Regards,

Andreas


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [FileUpload] Issue with multipart/form-data and request parameters in include

Posted by Martin Cooper <mf...@gmail.com>.
On 9/2/05, Andreas Schildbach <an...@schildbach.de> wrote:
> 
> Martin Cooper wrote:
> 
> >>1. GET: "value1 hello world value2"
> >>2. POST (default enctype): "value1 hello world value2"
> >
> > These are the only two combinations for which the container is required 
> to
> > make parameters available. See SectionSRV.4.1.1 of the Servlet 2.3 spec.
> 
> Thanks for this pointer! I have Servlet 2.4 spec available, but I guess
> it did not change much in this respect.
> 
> The important part is contained in SRV.4.1: "Data from the query string
> and the post body are aggregated into the request parameter set. [...]"
> 
> However, the container is not restricted to these two combinations. It
> could extend the aggregation behaviour to any parameter encoding it
> likes. I would go so far and assert that if the spec would someday be
> extended to enctype="multipart/form-data", the above aggregation rule
> would apply to this combination, too.


Probably, yes. But I'm not holding my breath for support of multipart in the 
Servlet spec. If they haven't done it by now, for whatever reason, it 
doesn't seem likely that it will ever happen. ;-(

--
Martin Cooper 


Regards,
> 
> Andreas
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

Re: [FileUpload] Issue with multipart/form-data and request parameters in include

Posted by Andreas Schildbach <an...@schildbach.de>.
Martin Cooper wrote:

>>1. GET: "value1 hello world value2"
>>2. POST (default enctype): "value1 hello world value2"
> 
> These are the only two combinations for which the container is required to 
> make parameters available. See SectionSRV.4.1.1 of the Servlet 2.3 spec.

Thanks for this pointer! I have Servlet 2.4 spec available, but I guess 
it did not change much in this respect.

The important part is contained in SRV.4.1: "Data from the query string 
and the post body are aggregated into the request parameter set. [...]"

However, the container is not restricted to these two combinations. It 
could extend the aggregation behaviour to any parameter encoding it 
likes. I would go so far and assert that if the spec would someday be 
extended to enctype="multipart/form-data", the above aggregation rule 
would apply to this combination, too.

Regards,

Andreas


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [FileUpload] Issue with multipart/form-data and request parameters in include

Posted by Martin Cooper <mf...@gmail.com>.
On 8/28/05, Andreas Schildbach <an...@schildbach.de> wrote:
> 
> Hello Brian,
> 
> I am sorry my last answer was a bit sloppy. For the sake of simplicity,
> please consider the following JSP 2.0 fragment:
> 
> --- fragment.jsp ---
> ${param.p}
> --- end fragment.jsp ---
> 
> This obviously outputs the parameter named p. Of course, my real
> fragment is much more complex than that, using an own controller and
> such (I was also using the words "plugin" and "portlet" because
> web-designers often use these. I was not talking about applets or
> embedded objects).
> 
> Ok, now here is a JSP which is the target of a form (I am skipping
> taglib defs):
> 
> --- target.jsp ---
> <c:import url="fragment.jsp?p=value1"/>
> hello world
> <c:import url="fragment.jsp?p=value2"/>
> --- end target.jsp ---
> 
> --- form.jsp ---
> <form action="target.jsp" method="post" enctype="multipart/form-data">
> [skipping form fields]
> </form>
> --- end form.jsp ---
> 
> (and yes, I did get jsp:include and c:import mixed up in my last post)
> 
> Now, here is what happens with the different methods for posting the form:
> 
> 1. GET: "value1 hello world value2"
> 2. POST (default enctype): "value1 hello world value2"


These are the only two combinations for which the container is required to 
make parameters available. See SectionSRV.4.1.1 of the Servlet 2.3 spec.

3. POST enctype="multipart/form-data": "hello world"


The container will not parse this (which is why you need Commons FileUpload 
in the first place), so the parameters are not being seen.

The thing to remember here is that the HTTP method and content encoding are 
preserved for request dispatcher calls within a request. That means that, 
since you submitted your form using #3 above, that same method and encoding 
will be used for the two <c:import>s, since those are implemented as request 
dispatcher includes.

As I wrote, I am wondering why 2 works but I am very happy about it. It
> would be great if 3 worked as 2.
> 
> I wonder what would be a reliable way to add parameters to included
> resources, that works regardless of the type of initial request.


Use request attributes instead of request parameters.

--
Martin Cooper


I am using FileUpload in a Spring
(springframework.org<http://springframework.org>)
> context, in a
> way that can be compared to a Servlet filter:
> 
> <bean id="multipartResolver"
> class="org.springframework.web.multipart.commons.CommonsMultipartResolver
> "/>
> 
> I hope I left no questions open this time. Sorry for that last
> inaccurate post.
> 
> Regards,
> 
> Andreas
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>