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

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Andreas Schildbach
Hi everyone,

I've got an issue with FileUpload 1.0:

I've got a form that posts with enctype="multipart/form-data". The
Controller decodes the request using FileUpload and forwards to a JSP,
which includes another resource with a parameter
("resource.jsp?param=value").

So, basically, there are form parameters in the body (encoded) AND there
are parameters in the URL as in a GET request.

Unfortunately, this "param" URL parameter is discarded, which is kind of
understandable, because FileUpload expects the parameters of the still
multipart/form-data request encoded in the request body.

However, with the default enctype for method="post" I can do that. I
don't know what the Servlet spec says on this topic. But could you maybe
also "map through" all parameters that are specified in the URL?
Basically, allow access to all parameters that are available in the
request, with body parameters taking precedence?

Regards,

Andreas


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Brian Cook

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


<form name="form" id="form" method="post" action="resource.jsp"
enctype="multipart/form-data">

     .....

   <input type="hidden" name="param" value="value" />

     .....


</form>

This would be much easier and more reliable that trying to make
commons.fileupload much more complicated.

If you have to do it the way you outlined then you might be able to pull
that value out of the HttpHeader object.



Andreas Schildbach wrote:

> Hi everyone,
>
> I've got an issue with FileUpload 1.0:
>
> I've got a form that posts with enctype="multipart/form-data". The
> Controller decodes the request using FileUpload and forwards to a JSP,
> which includes another resource with a parameter
> ("resource.jsp?param=value").
>
> So, basically, there are form parameters in the body (encoded) AND there
> are parameters in the URL as in a GET request.
>
> Unfortunately, this "param" URL parameter is discarded, which is kind of
> understandable, because FileUpload expects the parameters of the still
> multipart/form-data request encoded in the request body.
>
> However, with the default enctype for method="post" I can do that. I
> don't know what the Servlet spec says on this topic. But could you maybe
> also "map through" all parameters that are specified in the URL?
> Basically, allow access to all parameters that are available in the
> request, with body parameters taking precedence?
>
> Regards,
>
> Andreas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
Brian Cook
Digital Services Analyst
Print Time Inc.
[hidden email]
913.345.8900


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

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

Andreas Schildbach
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Brian Cook

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

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

Rahul Akolkar
In reply to this post by Andreas Schildbach
On 8/27/05, Andreas Schildbach <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Andreas Schildbach
In reply to this post by Brian Cook
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Martin Cooper
On 8/28/05, Andreas Schildbach <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

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

Andreas Schildbach
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Martin Cooper
On 9/2/05, Andreas Schildbach <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>