1. Download the latest COS pack (http://www.servlets.com/cos/index.html) and add it to Web-inf/bin
2. Can upload multiple files.
3. The main use of the class
Part
Parampart
Filepart
Multipartparser
The UpLoad () code is as follows: Import Com.oreilly.servlet.multipart. * ;
Private Boolean upLoad (HttpServletRequest request, Map < string,string > Parammap)
Throws IOException ... {
/**//*
* Set upload maximum length
*/
int maxSize = 2 * 1024 * 1024;
/**//*
* Upload Path
*/
String Uploadpath = Getservletcontext (). Getrealpath ("/")
+ Constants.picuploadpath;
/**//*
* Upload part to determine whether it is a file or a property
* If it is a file, take the relevant action if it is a property, remove the attribute and put it in a map for processing
*/
Part part = NULL;
Multipartparser mrequest = new Multipartparser (request, maxSize);
Mrequest.setencoding ("GBK");
while (part = Mrequest.readnextpart ())!= null) ... {
if (Part.isfile ()) ... {
/**//*
* Converted to Filepart
*/
Filepart Filepart = (filepart) part;
String fileName = Filepart.getfilename ();
if (fileName!= null && filename.length () > 0) ... {
Get extension
String fileextname = filename.substring (
Filename.lastindexof (".") + 1). toLowerCase ();
Upload pictures only
if (fileextname.equals ("JPEG") | | fileextname.equals ("JPG")
|| Fileextname.equals ("gif")) ... {
String NewFileName = util.getnewfilename () + "."
+ Fileextname;
String NewPath = Uploadpath + newfilename;
File NewFile = new file (NewPath);
Filepart.writeto (NewFile);
Parammap.put ("Picname", NewFileName);
} else
return false; Description upload is not a picture
else ... {
Continue Description did not choose to upload pictures
}
else if (Part.isparam ()) ... {
Parampart Parampart = (parampart) part;