Description: Need to add Commons-fileupload-1.2.2.jar and Commons-io-2.4.jar
The sample code for the operation is as follows:
<%
Fileitem item = (Fileitem) iter,next ();
if (!item.isformfileld ()) {
String Filename=item.getname ();
Create a fixed-length collection by using the Aslist () method of the Arrays class
list<string> FileType = arrays.aslist ("gif", "BMP", "JPG");
String ext = filename.substring (Filename.lastindexof (".") +1);
if (!filetype.contains (EXT)) {
Out.print ("Upload file failed, file type can only be gif,bmp,jpg");
}else{
if (filename!= null &&!filename.equals ("")) {
File FullFile = new file (Item.getname ());
File SaveFile = new file (Uploadfilepath,fullfile.getname ());
Item.wrtie (SaveFile);
Uploadfilename = Fullfile.getname ();
Out.print ("The file name after uploading is:" +uploadfilename);
}
}
}
%>
Using Commons-fileupload component to control file upload in JSP