附件上传报400错误,求大神看下是那个地方出问题?
御命丹心 2017-06-30 01:52:27 前端代码如下
<div class="control-group">
<label class="control-label">
<span class="help-inline"><font color="red">*</font></span>
营业执照上传:
</label>
<div class="controls">
<form id="file_upload_id" name="file_upload_name" enctype="multipart/form-data" method="post">
<input type="file" name="file_upload"/>
<input type="button" value="上传" id="temp"/><br>
</form>
<div>
<span id="typeValue"></span>
<input id="type" type="hidden" name="input_type">
</div>
<div>
<span id="sizeValue"></span>
<input id="size" type="hidden" name="input_size">
</div>
</div>
$("#temp").click(function () {
var formdata = new FormData($('#file_upload_id')[0]);
$.ajax({
url: '${ctx}/gsp/t01compinfonew/t01CompInfoNew/upload',
type: 'POST',
data: formdata,
dataType:'JSON',
cache: false,
processData: false,
contentType: false ,
success : function(date){
alert("success");
},
error : function(e){
alert("error");
}
});
})
});
后端代码如下:
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public HashMap<String,Object> upload(@RequestParam("file_upload")MultipartFile file,@RequestParam("input_type") String extName, @RequestParam("input_size") String size, HttpServletRequest request, HttpServletResponse response, ModelMap model) throws ServletException, IOException {
HashMap<String,Object> map = new HashMap<String,Object>();
request.setCharacterEncoding("UTF-8");// 解决上传的中文文件乱码问题
response.setContentType("text/html;charset=UTF-8");
long fileSizeMax=Long.parseLong(size);
String mes =t01CompInfoNewService.doUpload(file,request, extName, fileSizeMax);
map.put("mes", mes);
return map;
}
点击上传按钮报form:173 POST http://localhost:8080/jeesite/a/gsp/t01compinfonew/t01CompInfoNew/upload 400 (Bad Request)错误,求大神指点是什么地方出问题?调试了一天都没解决。