springboot jsp ajax 同时上传多个文件
jsp:
<form method="POST" action="" enctype="multipart/form-data" id="uploadform">
<input type="file" enctype="multipart/form-data" name="ufile" />
<input type="file" enctype="multipart/form-data" name="ufile"/>
<input type="button" value="上传" onclick="load()">
</form>
<script src="<%=request.getContextPath()%>/jss/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
function load(){
var fd = new FormData($("#uploadform")[0]);
$.ajax({
url: "upload?token=i389urf9du",
type: "POST",
data: fd,
processData: false,
contentType: false,
success : function(data) {
if(data.success){
alert("success");
}
},
error : function(data) {
alert(data.flag);
}
});
}
java
/**
* 文件接收
* @param files
* @param request
* @return
*/
@SuppressWarnings("rawtypes")
@RequestMapping(HwUnityID.PATH_UPLOAD)
@ResponseBody
public JKResult uploadFile(@RequestParam(value="ufile", required=false) MultipartFile[] ufile,
String token,HttpServletRequest request) {
if(ufile == null) {
return JKResult.fail(333);
}
for(MultipartFile file : ufile) {
hwFileUploadService.saveUploadFile(file, request);
}
return JKResult.success();
}