之前上传文件都是没有问题的,不知道为啥出现这样的问题:Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: Input length = 1?
前端是这样的:
<form enctype="multipart/form-data" id="batchUpload" action="" method="post" class="form-horizontal"> <table> <tr> <td > <input type="file" name="file" style="width:0px;height:0px;" id="uploadEventFile"> <input id="uploadEventPath" disabled="disabled" type="text" placeholder="请选择excel表" style="border: 1px solid #e6e6e6; height: 115px;width: 400px;" > </td> </tr> <tr> <td align="center"> <cui:button label="选择文件" id="uploadEventBtn" componentCls="btn-primary" style="height:40px;width :185px" type="button" /> <cui:button label="上传文件" type="button" componentCls="btn-primary" style="height:40px;width :183px" onClick="uploadBtn()" /> </td> </tr> </table> </form>
js:
$(function(){ //模拟上传excel $("#uploadEventBtn").unbind("click").bind("click",function(){ $("#uploadEventFile").click(); }); $("#uploadEventFile").bind("change",function(){ $("#uploadEventPath").attr("value",$("#uploadEventFile").val()); }) }); //点击上传按钮 function uploadBtn(){ debugger; var uploadEventFile = $("#uploadEventFile").val(); if(uploadEventFile == ''){ $.message({message:"请选择excel,再上传!", cls:"waring"}); }else if(uploadEventFile.lastIndexOf(".xls")<0){//可判断以.xls和.xlsx结尾的excel $.message({message:"只能上传Excel文件!", cls:"waring"}); }else{ debugger; var formData = new FormData($("#batchUpload")[0]); var ul = '${ctx}/zbgl/zbbp/validateDutydate'; $.loading({text:"正在处理中,请稍后..."}); $.ajax({ url: ul, type: "POST", data:formData, dataType: "json", processData: false, // 告诉jQuery不要去处理发送的数据 contentType: false, // 告诉jQuery不要去设置Content-Type请求头 success: function (data) { debugger; if(data.code == "1"){ $.loading("hide"); $.message({message:data.msg, cls:"waring"}); }else if(data.code == "300"){ $.loading("hide"); $.message({message:data.msg, cls:"waring"}); }else if(data.code == "500"){ $.loading("hide"); $.message({message:"操作失败!", cls:"waring"}); } else if(data.code == "200") { } }); } };
controller层:
@RequestMapping(value = "/validateDutydate") @ResponseBody @Logger(action = "获取", logger = "获取传入的excal文件", model = "值班编排") public Map<String, Object> validateDutydate(MultipartFile file, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> map = new HashMap<>(); try { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; // 获取传入文件 InputStream inputStream = file.getInputStream(); zbbpService.validateDutydate(inputStream); map.put("code", 200); } catch (AlreadyHasDutyListOnDutyDayException duty) { duty.printStackTrace(); map.put("code", 1); map.put("msg", duty.getMessage()); } catch (IOException e) { e.printStackTrace(); map.put("code", 300); map.put("msg", "文件读取异常!"); } catch (Exception e) { e.printStackTrace(); map.put("code", 500); } return map; }
后端一直进不去,这是什么问题?
不知道你这个问题是否已经解决, 如果还没有解决的话: