1.jsp使用from.submit表单提交;
2接口封装
public static List<MultipartFile> uploadFile (HttpServletRequest request){
List<MultipartFile> multipartFileList=null;
CommonsMultipartResolver multipartResolver=new CommonsMultipartResolver(request.getSession.getServletContext());//创建通用的多部分解析器
if(multipartResolver.isMultipart(request)){//判断request是否有文件存在
MultipartHttpServletTrquest mulRequest=(MultipartHttpServletRequest)request;//转成多部分request
Iterator<String> filenames=mulRequest.getFileNames();//获取所有文件
multipartFiles=new ArrayList<MultipartFile>();
while (filenames.hasNext()){
//记录上传过程起始时间,用来计算时间
int pre=(int)System.currentTimeMillis();
//获取上传的文件
MultipartFile file=mulRequest.getFile(filenames.next());
multipartFiles.add(file);
}
return multipartFiles;
}}