Solve the problem that the Post submission form (file upload) Request.getparameter the null value

Source: Internet
Author: User

When you encounter a form that has both a file upload and a Received field, the field wants to be request.getparameter, often null.

<form action= "FileUpload" method= "post" enctype= "Multipart/form-data" Name= "Form1" > 
   <input type= "text" Name= "text" >
   <input type= "file" name= "file" > 
    <input type= "button" Name= "Submit" value= "Upload" Onclick= "OK ()" > 
</form>

As above, call Request.getparameter ("text") in the public void DoPost (HttpServletRequest request, httpservletresponse response) To get a null

How to get it. There are two kinds of solutions

1, with two forms: (More trouble)
A from that uses a file submitted by post to upload from, a field that takes a get commit, and then the value of the second form as the first argument

function ok ()  { 
       var name = Form2.name.value; 
       var title= form2.title.value; 
       form1.action= "Fileupload?name=" +name+ "&title=" +title; 
       Form1.submit (); 
 }

2,commons-fileupload Judge FieldName, to distinguish whether the file is uploaded or field

Servletfileupload upload = new Servletfileupload (factory);    
try {    
     List  items = upload.parserequest (request);    
     for (Iterator i = Items.iterator (); I.hasnext ();) {    
                Fileitem Fileitem = (fileitem) i.next ();    
                String field = Fileitem.getfieldname ();  Judge FieldName,  
                if (field.equals ("kind")) {    
                          kind = fileitem.getstring ();    
                          Continue;    
                } else if (field.equals ("id")) {    
                         id = fileitem.getstring ();    
                         Continue;    
                } else if (field.equals ("topic")) {    
                         topic = fileitem.getstring ();    
                         Continue    
                

3, JSP SmartuploadSpecifically provided Smartupload.getrequest (). GetParameter ("text")
A specific introduction to see me another blog http://blog.csdn.net/jazywoo123/article/details/7900114



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.