-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

André,

(Man, I need to get a keyboard mapping for "é". This copy-and-paste
thing is such a drag...)

On 3/16/2009 6:09 PM, André Warnier wrote:
> Christopher Schultz wrote:
>>
>> Quick question: multipart/form-data is typically used for file upload...
>> why not use application/x-www-form-urlencoded instead? I realize the
>> problem is that certain browsers do not send the proper charset in the
>> Content-Type, but I'd like to understand your affinity for
>> multipart/form-data.
>>
> This :
> http://www.w3.org/TR/html401/interact/forms.html#h-17.13
> See the note in green at the end of 17.13.1 Form submission method.

The W3C docs for 'enctype' mentions that multipart/form-data should be
used with <input type="file" />
http://www.w3.org/TR/html401/interact/forms.html#adef-enctype

> Plus, the fact that our applications (area : document management) very
> often do offer the possibility to upload a file from within forms.

Gotcha.

> Plus, the fact that the same applications often do offer the possibility
> to submit very large non-USASCII text fields.

The size of the fields shouldn't be an issue, unless you want to stream
the data yourself. But you mentioned using getParameter, so you're /not/
streaming the data yourself.

> Plus, the fact that most of my activity relates to users who are not
> mainly English-speaking and do not use a US keyboard to fill-in web forms.
> Plus, the fact that having seen HTTP/HTML being born, I remember the
> time when URL's were typically limited in size, in a manner inconsistent
> between platforms. That might still be the case.

It is :)

> Somewhat abusively I admit, I took an early aversion to
> application/x-www-form-urlencoded, as synonymous to GET, to non-capable
> of anything but US-ASCII (ok, iso-8859-1 at a stretch, but see the above
> green note) and to "nobody agrees as to the proper percent encoding and
> at what moment it should take place or not".

No, it will work and its better that GET because it's encoded using the
Content-Type of the request, rather than God-knows-what given the
browser settings.

> The multipart/form-data encoding does not have all of these
> connotations, and should be a foolproof way for a browser to send data
> to a server without any size limit or charset ambiguity.

The only differences I see between multipart/form-data and
application/x-www-urlencoded encoding types are the W3C's choice for the
default and the servlet spec's requirement (both x-www) and the W3C's
statement about <input type="file" />.

> It is also a big disappointment to see (you are right, I checked) that
> the Servlet Spec does not foresee a simple method to get the parameter
> values if they are posted via the multipart/form-data encoding method.

This is because the implication of using multipart/form-data is that the
app code will read its own stream. If you upload a 100MB file, do you
want that whole thing in memory as a (useless) String value?

> That is probably because for 10 years or so, I have been using this
> under Apache and perl without any problems at all : I just use the
> equivalent of GetParameter() there, without having to worry a jot about
> the request encoding; and why should I have to ?

So what is Perl's default charset? I find it hard to believe that Perl
just magically works with the same missing charset information.

> Read the body myself and parsing it ? in 2009 ?

Yes, read it yourself. You told the servlet container that you wanted to
do it. I'm actually surprised that getParameter() gets you any of your
POST form data when using multipart/form-data. You never did say how it
failed: do you get a bad String (misinterpreted) or do you get null
because getParameter didn't parse the request?

> Now come on, I am sure that there must exist some standard Java library
> usable in a servlet context, and which does that, no ?

You can use commons-upload, which was intended to be used with file
uploads, and will probably read "simple" multipart/form-data fields as well.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkm+2qcACgkQ9CaO5/Lv0PASywCcDJ1ZonoXKXuHp7SyUa3M6qeD
/ogAnii33RObyJ6HJvLkLEyBf+F8jQKZ
=3ArQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to