When a JSP form contains the upload function, other content that cannot be obtained is displayed.

Source: Internet
Author: User

On a page, if the submitted form (that is, form) contains the upload function, if the other content information of the form is not properly processed, the result of null is returned. I believe a friend with the same problem obtains the content as follows: "request. getParameter ("content name"); "(of course, you must add the enctype =" multipart/form-data "attribute to complete the upload in form "). So what should I do if I cannot get it like this? In this case, you need to handle it like this: SmartUpload su = new SmartUpload (); // declare a SmartUpload object su. initialize (pageContext); // upload and initialize myFile1.saveAs (saveurl1, SmartUpload. SAVE_PHYSICAL); // upload and save the file // obtain the user input name String name = su. getRequest (). getParameter ("username"); [Note: the code that adds a horizontal line is the key to obtaining other content in the form. It is a bit like obtaining a normal request. Note that this statement must be executed after the file is uploaded and saved, that is, after "myFile1.saveAs (saveurl1, SmartUpload. SAVE_PHYSICAL); // file upload and save "after this statement] the reason why this problem occurs when I obtain other forms is probably checked on the Internet. This is the reason: upload is transmitted through byte streams, while other content in the form is transmitted through text. Therefore, when the form is transmitted together, the obtained result is null. (You are welcome to correct the cause, but I called it for one night last night, if such a problem occurs, you can solve it in this way ).

Related Article

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.