Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 处理程序执行导致异常:必需的MultipartFile参数';文件';不在场_Javascript_Java_Spring_Multipartform Data_Multipart - Fatal编程技术网

Javascript 处理程序执行导致异常:必需的MultipartFile参数';文件';不在场

Javascript 处理程序执行导致异常:必需的MultipartFile参数';文件';不在场,javascript,java,spring,multipartform-data,multipart,Javascript,Java,Spring,Multipartform Data,Multipart,我的控制器代码: @RequestMapping(value = "/rest/auth/admin/test/responseTest", method = RequestMethod.POST) @ResponseBody public ResponseEntity<ResponseVO> responseTest(@RequestParam("file") MultipartFile file, @RequestParam(value = "testId", r

我的控制器代码:

@RequestMapping(value = "/rest/auth/admin/test/responseTest", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<ResponseVO> responseTest(@RequestParam("file") MultipartFile file,
        @RequestParam(value = "testId", required = true) long testId) {
当我调用上述Ajax时,我在服务器端遇到以下错误

[org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] > logException() : 186 - Handler execution resulted in exception: Required MultipartFile parameter 'file' is not present

请帮助我解决此问题。

我本以为此文件的contentType头应该是multipart/form data,而不是application/json

var fd = new FormData();
fd.append('file', $('input[type=file]')[0].files[0]);
fd.append("label", "WEBUPLOAD");
var headers = {};
headers[Constants.XCSRFTOKENCookieName] = util.getCookie(Constants.XCSRFTOKENCookieName);
var url = "rest/auth/admin/test/responseTest?responseTest=123";
var dataType = "json";
var contentType = "application/json";
$.ajax({
    url: url,
    type: "POST",
    data: fd,
    dataType: dataType,
    async: isAsync,
    headers: headers,
    enctype: contentType,
    processData: false, // tell jQuery not to process the data
    contentType: false, // tell jQuery not to set contentType
    success: function(result, status, jqXHR) {
        resultObj = result;
        if (successCallBack != null) {
            successCallBack(resultObj);
        }
        //util.hideLoader();
    },
    error: function(jqXHR, textStatus, errorThrown) {
        console.log("Error : " + errorThrown);
        resultObj = jqXHR.responseJSON;
        if (errorCallBack != null) {
            errorCallBack(resultObj);
        }
        //util.hideLoader();
    }
});
[org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] > logException() : 186 - Handler execution resulted in exception: Required MultipartFile parameter 'file' is not present