Jquery 代码
<script type="text/javascript">
$(document).ready(function() {$("#uploadify").uploadify({
'auto' : false,
'swf' : '${ctx }/script/uploadify.swf',
'uploader' : '${ctx }/service/saveServiceEnPdf.do',//后台处理的请求
'queueID' : 'fileQueue',//与下面的id对应
'queueSizeLimit' : 2000,
'fileTypeDesc' : 'pdf',
'fileTypeExts' : '*.pdf', //控制可上传文件的扩展名,启用本项时需同时声明fileDesc
'multi' : true,
'buttonText' : '选择文件'
});
});
</script>
</head>
<body>
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<p>
<a href="javascript:$('#uploadify').uploadify('upload', '*')">开始上传</a>
<a href="javascript:$('#uploadify').uploadify('cancel', '*')">取消上传</a>
</p>
</body>
JAVA 代码
@RequestMapping(value = "/saveServiceZhPdf", method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public Map<String, Object> saveServiceZhPdf(Schedule schedule,HttpServletRequest request, HttpServletResponse response, ModelMap model) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
String fileName = "";
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile mf = entity.getValue();
fileName = mf.getOriginalFilename();
System.out.println("FileName: " + fileName);
String path = request.getSession().getServletContext().getRealPath("upload/upload_service/ZH");
File targetFile = new File(path, fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
//保存
try {
mf.transferTo(targetFile);
serService.updateAllService(serService.findAll());
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}