users@glassfish.java.net

Re: Servlet 3.0: multipart/form-data and getParameter / getPart not working as expected

From: Steven Siebert <smsiebe_at_gmail.com>
Date: Wed, 4 Aug 2010 13:39:08 -0400

Hi Dominik,

When you're using multipart, use getPart() to get your parameter value. You
must then turn it to string.

Part myStringPart = request.getPart("myFormFieldName");
Scanner scanner = new Scanner(myStringPart.getInputStream());
String myString = scanner.nextLine();

Cheers,

Steve


On Wed, Aug 4, 2010 at 10:39 AM, Dominik Dorn <dominik.dorn_at_gmail.com>wrote:

> Hi,
>
> I'm having issues with a form with enctype='multipart/form-data' and a
> servlet
>
> The form has 9 normal text input fields and one upload (input
> type='file') field.
> Without the enctype='multipart/form-data' I can access the normal form
> fields
> with request.getParameter(); however, when adding the enctype,
> request.getParameter
> always returns null.
>
> When I try to access the text-fields through getPart they are declared as
> FILES!
>
>
> [#|2010-08-04T16:29:12.059+0200|INFO|glassfishv3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=24;_ThreadName=http-thread-pool-8080-(1);|req.getPart("language")
> = File name=null,
>
> StoreLocation=/home/domdorn/skriptum/upload/upload__5741d6e7_12a3d610371__7ff8_00000034.tmp,
> size=2bytes, isFormField=true, FieldName=language|#]
>
> language is actually just "en".
>
> How should I access this? It's not appropriate to create an
> inputstream/reader just for getting out 2 characters....
>
> Shouldn't the servlet implementation look if the content-type of the
> part is actually really a file and not text/plain ?
>
> I would expect the normal textfields available through
> request.getParameter(...) and only the file accessible through
> request.getPart(...);
>
>
> Thanks,
> Dominik
>
> --
> Dominik Dorn
> http://dominikdorn.com
> http://twitter.com/domdorn
>
> Tausche Deine Lernunterlagen auf http://www.studyguru.eu !
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>