Smartupload is used to obtain form data during File Upload (recommended), and smartupload uploads images
Form forms for file upload must meet two conditions:method="post" enctype="multipart/form-data"
In the form, enctype = "multipart/form-data" means to set the MIME encoding of the form. By default, the encoding format is application/x-www-form-urlencoded and cannot be used for file upload. Only multipart/form-data can be used to completely transmit file data. Enctype = "multipart/form-data" is used to upload binary data. The input values in form are passed in binary format. Therefore, the request will not get the value. That is to say, if this code is added, the request will fail to be passed.
The following method is used to obtain the value of a form field:
SmartUpload su = new SmartUpload (); // create a new SmartUpload object su. getRequest (). getParameterValues (String name); // retrieves the array value su. getRequest (). getParameter (String name); // obtain a single parameter value
Note: When Using SmartUpload, you need to add the corresponding jar package
String softname=su.getRequest().getParameter("softname");
Note: You must use su. upload (); to obtain the value !!
<Span style = "font-size: 14px;"> public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {SmartUpload mySmartUpload = new SmartUpload (); try {// Initialization mySmartUpload. initialize (config, request, response); mySmartUpload. setMaxFileSize (10*1024*1024); // restrict the size of the uploaded file // mySmartUpload. setAllowedFilesList ("txt, html, jpg, js"); // sets the file type mySmartUpl that can be uploaded. Oad. setDeniedFilesList ("exe, doc"); // sets the list of files to be uploaded. 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 ++) {// Upload File of multiple files = mySmartUpload. getFiles (). getFile (I); if (file. getSize ()! = 0) {// The new name String fileNameString = System. currentTimeMillis () + ". "+ file. getFileExt (); // you can use the actual servlet path to piece together the storage path of the uploaded file. You need to modify the 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. printStackTrace () ;}</span>