jquery.fileupload 批量上传

<script>
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
url:'${pageContext.request.contextPath}/qua/quaCheckAction!checkUploadFile.action',
start: function (e, data) {
parent.$.messager.progress({
title : $.i18n.prop('msg_show_title'),
text : $.i18n.prop('msg_show_text')
});
},
stop:function(){
parent.$.messager.progress('close');
$.messager.show({
title:$.i18n.prop('msg_show_title'),
msg:$.i18n.prop('upload_success'),
timeout:5000,
showType:'slide'
});
}
/* done: function (e, data) {
debugger
parent.$.messager.progress('close');
//导入成功
$.messager.show({
title:$.i18n.prop('msg_show_title'),
msg:$.i18n.prop('upload_success'),
timeout:5000,
showType:'slide'
});
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
} */
})
});

function uploadFiles(){
$('#fileupload').click();
};

</script>

<input id="fileupload" type="file" name="files" multiple style="display: none">
<a data-btn="btn_upload_many" onclick="uploadFiles();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'">批量上传</a>

private File files;// 文件 批量上传使用
private String filesFileName;// 文件名称 批量上传使用
private String filesContentType;// 文件类型 批量上传使用

/**
* @liutt
* 批量上传时使用该方法上传
*/
public void checkUploadFile(){

//String filePath = getSavePath(); // 获取文件夹的路径

String url = ServletActionContext.getServletContext().getRealPath("/");
File file = new File(url);
String newFilePath = file.getParentFile().getParentFile().getParentFile().getPath()+"/check";
File newFile = new File(newFilePath);
// 如果不存在文件夹 就创建一个文件夹
if (!newFile.exists() && !newFile.isDirectory()) {
newFile.mkdirs();
}
// 获取文件夹的路径 和 重命名后的文件的名称
String checkfilepath = newFile.getPath() + "\" + getFilesFileName();
try {
FileUtils.wirteFile(checkfilepath, getFiles());
//将文件路径和数据库进行绑定
quaCheckFileService.saveQuaCheck(getFilesFileName(), "check");
} catch (Exception e) {
e.printStackTrace();
super.writeJson("error");
return;
}
}

原文地址:https://www.cnblogs.com/liutt1989/p/6401077.html