Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
Java 角度弹簧文件上传_Java_Angularjs_Spring_Spring Mvc - Fatal编程技术网

Java 角度弹簧文件上传

Java 角度弹簧文件上传,java,angularjs,spring,spring-mvc,Java,Angularjs,Spring,Spring Mvc,我正试图点击Spring RestController并得到: o、 s.web.servlet.PageNotFound:不支持请求方法“POST” 我相信控制器的地图上少了一些东西 <div class="col-sm-1" style="background-color:#cccccc;" align="center"><span class="file-input btn btn-primary btn-file">Import file<input typ

我正试图点击Spring RestController并得到:

o、 s.web.servlet.PageNotFound:不支持请求方法“POST”

我相信控制器的地图上少了一些东西

<div class="col-sm-1" style="background-color:#cccccc;" align="center"><span class="file-input btn btn-primary btn-file">Import file<input type="file" onchange="angular.element(this).scope().uploadScriptFile(this.files)"></input></span></div>


    $scope.uploadCtrFile = function(files) {
        console.log(">>>>>>>>>>>>>>>>uploadCtrFile");
        var fd = new FormData();
        //Take the first selected file
        fd.append("file", files[0]);
        console.log(">>>>>>>>>>>>>>>>uploadCtrFile angular.toJson: "
                + angular.toJson(fd, 2));

        $http.post('/rest/uploadCtrFile/', fd,{
            withCredentials: true,
            headers: {'Content-Type': undefined },
            transformRequest: angular.identity
        }).success(function(fd, status, headers, config) {
            $scope.success = ">>>>>>>>>>>>>>>>uploadCtrFile Success: "+JSON.stringify({data: fd});
            console.log($scope.success);
        })
        .error(function(fd, status, headers, config) {
            $scope.success = ( "failure message: " + JSON.stringify({data: fd}));
            console.log($scope.success);
        });

    };

我缺少什么?

您将
未定义的
作为
内容类型的值发送,如下所示:

headers: {'Content-Type': undefined }
但是控制器需要
内容类型
多部分/表单数据
值:

@RequestMapping(..., headers = "'Content-Type': 'multipart/form-data'", ...)
您应该在请求中发送正确的
内容类型
标题,如:

headers: {'Content-Type': 'multipart/form-data'}
或者从控制器定义中删除
标题
选项:

@RequestMapping(value = "/uploadCtrFile/", method = RequestMethod.POST)
headers: {'Content-Type': 'multipart/form-data'}
@RequestMapping(value = "/uploadCtrFile/", method = RequestMethod.POST)