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" +java.io.file.separator+filenamestring;
File.saveas (path);
} thread.sleep (100); /* Download the file statement mysmartupload.downloadfile ("/path" + "file name"); */}}catch (Exception e) {e.printst
Acktrace (); }}</span>