码迷,mamicode.com
首页 > Web开发 > 详细

简单的servlet上传文件

时间:2018-05-15 19:32:38      阅读:219      评论:0      收藏:0      [点我收藏+]

标签: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>

简单的servlet上传文件

标签:boolean   direct   exce   lis   Servle   request   response   upload   mfa   

原文地址:https://www.cnblogs.com/shanshen/p/9042430.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!