users@glassfish.java.net

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

From: Dominik Dorn <dominik.dorn_at_gmail.com>
Date: Wed, 4 Aug 2010 16:39:41 +0200

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 !