You can use the jspsmartupload control to upload a file with a parameter. Solution servlet cannot process the request. getparameter () parameter.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.