Smartupload to get form data when uploading files (recommended) _javascript tips

Source: Internet
Author: User

form forms that implement file uploads must meet two conditions:method="post" enctype="multipart/form-data"

The enctype= "Multipart/form-data" in the form means that the MIME encoding of the form is set. By default, this encoding format is application/x-www-form-urlencoded and cannot be used for file uploads, and only multipart/form-data can be used to complete the delivery of file data. Enctype= "Multipart/form-data" is the uploading of binary data; The value of the input in the form is passed in binary form. So the request will not get the value, that is, add this code, use request will pass unsuccessful.

When you take a form field value, use the following method:

Smartupload su = new Smartupload (); Creates a new Smartupload object 
su.getrequest (). Getparametervalues (String name);//Fetch array values  

Note: You need to add the appropriate jar package when using Smartupload

String softname=su.getrequest (). GetParameter ("Softname");

Note: Must be in Su.upload (), after use, before you can get the value!!

<span style= "FONT-SIZE:14PX;" >public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioexcepti 
      on {smartupload mysmartupload = new Smartupload (); 
        try{//initialization mysmartupload.initialize (config,request,response); Mysmartupload.setmaxfilesize (10*1024*1024);//Limit the size of the uploaded file//mysmartupload.setallowedfileslist ("Txt,html,jpg,js"); 
        /Set the file type allowed to upload mysmartupload.setdeniedfileslist ("Exe,doc");/set the list of files that are prohibited from uploading mysmartupload.upload (); 
        String hstring = Mysmartupload.getrequest (). GetParameter ("name1"); 
        System.out.println (hstring); 
        System.out.println (Mysmartupload.getfiles (). GetCount ()); for (int i = 0; I <mysmartupload.getfiles (). GetCount (); i++) {//Multiple files Upload file = Mysmartupload.getfiles (). GE 
          Tfile (i); if (File.getsize ()!=0) {//piecing together the new name of the uploaded file String filenamestring = System.currenttimemilliS () + "." 
            +file.getfileext (); 
            Through the actual path of the servlet to put together the save path of the uploaded file, the actual use needs to modify this path String path = "/upload123123"; 
          File.saveas (path); 
          } thread.sleep (100); /* Download the file statement mysmartupload.downloadfile ("/path" + "file name"); */}}catch (Exception e) {e.printst 
      Acktrace ();  }}</span>

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: 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.