JSP Upload and parameter passing : issue of enctype attribute of form element
Posted on 2004-08-06
i have a tricky question sir, though im just new to servlet.
I have a jsp file that calls a servlet, i had managed to upload file fortunately
and i think i need to specify the enctype attribute of form element to
"multipart/form-data", to comply file upload. everything works to this point
in my servlet that downloads the file.
When i remember that i also need to pass the username in request parameter,
I add a text element in my jsp file, and when i try again
the upload still works but i always get a null value whenever i access the request parameter
finally i resolved to do something like this:
now i don't get null anymore when i access the username request parameter
but this time i got error when i try to upload a file.
what does enctype means? will it only choose one when it goes to the request object
and will not choose again if it already choose one?
OR CAN I CHANGE THE ENCTYPE OR CONTENTTYPE OF THE REQUEST OBJECT INSIDE SERVLET?
What should i do now sir/madam for me to read both file upload and string (object) value in request parameter?
here is part of my codes:
<form name="form1" enctype="multipart/form-data/application/x-www-form-urlencoded" method="post" action="../servlet/Uploader.uploadRename" >
<input type="text" size="23" name="username" value="jemjem" >
<input type="file" accept="image/*" name=photo maxlength="50" size="50">
<input type="reset" value="Reset" name="Reset">
<input type="submit" name="mybutton" value="Upload Photo" onclick="return checkExt()" >
Note: IM USING ORIELLY PACKAGE HERE. THANKS.
public void doPost ( HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException
String ngcId = (String) req.getParameter( "ngcId" );
System.out.println("------------------> " + ngcId );
MultipartRequest mpr = new MultipartRequest( req, path, 5*1024*1024);
THANKS IN ADVANCE FOR ANY HELP. I REALLY NEED THIS. THANKS.