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/27 08:23:10 UTC

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

Brian Cook wrote:

> Is there a reason that the URL parameters can not be included as a 
> hidden field in the form?  i.e. Instead of setting a form tag with the 
> action set to "resource.jsp?param=value".  Set up your form to post the 
> value with the form as a hidden form field set up

The reason is that from the form, I am including another resource (kind 
of a plugin/fragment/portlet), which hasn't got a clue if it is included 
in a POST or GET request.

Is there a way at all to set a hidden parameter with JSTL <c:include ...>?

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

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

Posted by Andreas Schildbach <an...@schildbach.de>.
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 Brian Cook <bc...@printtime.com>.
> Brian Cook wrote:
> 
>> Is there a reason that the URL parameters can not be included as a 
>> hidden field in the form?  i.e. Instead of setting a form tag with the 
>> action set to "resource.jsp?param=value".  Set up your form to post 
>> the value with the form as a hidden form field set up
> 
> Andreas Schildbach wrote:
 >
> The reason is that from the form, I am including another resource (kind 
> of a plugin/fragment/portlet), which hasn't got a clue if it is included 
> in a POST or GET request.
> 
> Is there a way at all to set a hidden parameter with JSTL <c:include ...>?
> 
> Regards,
> 
> Andreas



Ok I am not trying talk down to you or be a jerk here but you really 
have be specif on these kinds of forums.

What specifically is this "plugin/fragment/portlet"?  Is this a JSP page 
fragment/segment?  A Java Object of some kind? An Applet?  A web start 
object?  What?

I am afraid I can not give you any intelligent answers on JSTL but as 
long as you can read the parameters from it then you should be able to 
add a getParamtersFrom() function to a Java Bean or write a custom JSP 
tag to add the parameters from this extra resource as hidden fields.



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

Posted by Rahul Akolkar <ra...@gmail.com>.
On 8/27/05, Andreas Schildbach <an...@schildbach.de> wrote:
> Brian Cook wrote:
> 
> > Is there a reason that the URL parameters can not be included as a
> > hidden field in the form?  i.e. Instead of setting a form tag with the
> > action set to "resource.jsp?param=value".  Set up your form to post the
> > value with the form as a hidden form field set up
> 
> The reason is that from the form, I am including another resource (kind
> of a plugin/fragment/portlet), which hasn't got a clue if it is included
> in a POST or GET request.
> 
> Is there a way at all to set a hidden parameter with JSTL <c:include ...>?
<snip/>

The JSTL core taglib does not have a <c:include> tag. It does have a
<c:import> tag, which I think you might be refering to, and params can
be passed in via <c:param> children (tags).

-Rahul


> 
> Regards,
> 
> Andreas

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