Today, I encountered a file upload issue, but I still need to obtain other form data while uploading the file. The operations for uploading files and obtaining form data are all processed in the servlet.
: Http://download.csdn.net/source/2100914 for jspsmartupload
Form used to upload data:
<Form name = "form1" method = "Post" Action = "Servlet/upfile" enctype = "multipart/form-Data">
<P> enter the mobile phone number </P>
<P>
<Input type = "text" name = "phone" value = "1234567890"/>
</P>
<P> upload images (only in *. gif and *. jpg files) </P>
<P>
<Input type = "file" name = "file1"/>
</P>
<P>
<Input type = "Submit" name = "Submit" value = "· submit ·"/>
</P>
</Form>
Submitted backend Servlet
Smartupload su = new smartupload ();
Su. initialize (this. getservletconfig (), request, response );
String realpath = This. getservletcontext (). getrealpath ("");
String Path = realpath + "/images ";
Su. setallowedfileslist ("GIF, jpg ");
Su. Upload ();
Int COUNT = Su. Save (PATH );
Msdnid = Su. getrequest (). getparameter ("phone"); // note that this is a parameter passed through the receiving form.
System. Out. println ("msdnid =" + msdnid );
//////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////
Note: The statements used to receive form parameters must be placed behind the Su. Upload (); statement, that is, they must be received after the file is uploaded. Otherwise
No matter how you try to receive the result, it is always "null ".
I tried it two minutes before I got dizzy. It's really not easy !!!!!
After the above problem is solved, all garbled characters are received when the passed parameters are Chinese characters. After repeated experiments, the encoding format of the form page is set to "gb2312.