Commons-fileupload Upload File (1), commons. fileupload
Recently, I used the commons-fileupload component to write an image upload function. Submitted form to the background (structs framework is not used here), and List pl = dfu in the background. parseRequest (request); Iterator iterator = pl. iterator (); the length of iterator is always zero. If the input parameter passed in is not of the type = file type, the request cannot be used. getParameter () is obtained. This is because the content type submitted by form is "multipart/form-data". Now we must use the parseRequest (request) method; parseRequest () the parseRequest method parses the data of fields in the form, encapsulates the data into independent fileItem objects, and adds these fileItem objects to a list-type Collection object. Then all parameters must be obtained through iterative iterator, and isFormField is used to determine whether they belong to a common form field. Here we just mentioned that the iterator length is zero because we didn't give the name attribute to the label in form, for example: <input type = "file" value = "Upload image" name = "uploadImage"/>.
Demo download: http://download.csdn.net/detail/u014458334/8895899
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.