标签:boolean direct exce lis Servle request response upload mfa
boolean multipartContent = ServletFileUpload.isMultipartContent(request);
if (multipartContent==true) {
DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(fileItemFactory);
upload.setSizeMax(40 * 1024 * 1024);
List<FileItem> fileItemList = upload.parseRequest(request);
for (FileItem fileItem : fileItemList) {
File file1 = new File("E:\\app\\" + fileItem.getName());
try {
fileItem.write(file1);
} catch (Exception e) {
e.printStackTrace();
}
}
}
response.sendRedirect("/hello.jsp");
maven配置:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
标签:boolean direct exce lis Servle request response upload mfa
原文地址:https://www.cnblogs.com/shanshen/p/9042430.html