upload.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/quick19" method="post" enctype="multipart/form-data">
上传文件<input type="file" name="uploadFile"><br/>
上传文件<input type="file" name="uploadFile"><br/>
<input type="submit" value="提交">
</form>
</body>
</html>
controller层
@RequestMapping(value = "/quick19",produces = "text/html;charset=utf-8")
@ResponseBody
public String save19(MultipartFile[] uploadFile) throws IOException {
for (MultipartFile file : uploadFile) {
String originalFilename = file.getOriginalFilename();
file.transferTo(new File("E:\\"+originalFilename));
}
return "上传成功";
}
配置文件
<!-- 配置文件上传-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"/>
<property name="maxUploadSize" value="500000"/>
</bean>
pom.xml依赖
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
原文:https://www.cnblogs.com/codegzy/p/14806830.html