注意这边要加入jar包,
String filePath=getServletContext().getRealPath("/")+"file";
File file=new File(filePath);if(!file.exists()){
file.mkdir();
}
SmartUpload upload = new SmartUpload();
Request req = upload.getRequest();
try{
upload.initialize(getServletConfig(), request, response);
// 允许上传的文件类型
upload.setAllowedFilesList("doc,xls,txt,docx");
// 拒绝上传的文件类型
try {
upload.setDeniedFilesList("exe,bat,jsp");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 允许上传文件的单个最大大小
upload.setMaxFileSize(1024 * 1024 * 20);
// 允许上传文件的最大大小总和
upload.setTotalMaxFileSize(1024*1024*10);
//上传数据
upload.upload();
int count=upload.save(filePath);
System.out.println(count);
}
catch (SmartUploadException e){
e.printStackTrace();
return;
}
String emaill= req.getParameter("?"); //这边可以取上传的数据