如何从imput type =" file"中发送数据?到控制器?

时间:2015-08-19 13:31:21

标签: java jquery ajax jquery-file-upload

我在ftl:

<input type="file" id="doc6" name="documente">
<。>在.js:

var lx = $("#longX").val();
var ly = $("#latY").val();
var jud = $("#judetPunctLucru").val();
var doc6Type = $("#doc6Type").val();
var doc6 = $('doc6').val();

validateCoords: function (lx, ly, jud, doc6Type, doc6) {
            var data = {
                lx: lx,
                ly: ly,
                jud: jud,
                doc6Type: doc6Type,
                doc6: doc6
            };
            var url = contextPath + '/validareCoord';
            return getJSONData(url, data);
        }

并在控制器中:

@RequestMapping(value = "/validareCoord", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Map<String, Object> getValidCoord(@RequestParam("lx") String lx,
                                             @RequestParam("ly") String ly,
                                             @RequestParam("jud") String jud,
                                             @RequestParam(value = "doc6Type", defaultValue = "") final String doc6Type,
                                             @RequestParam(value = "doc6", required=false) MultipartFile doc6){
.....
}

但是doc6不是我所需要的,当我这样读它时,错误是:

ERROR:
org.springframework.web.multipart.MultipartException: The current request is not a multipart request

你能告诉我应该如何从文件中读取数据吗?显然var doc6 = $('doc6').val();它不行。

1 个答案:

答案 0 :(得分:0)

您应该尝试在@RequestMapping中添加标题:

headers = "content-type=multipart/*"
相关问题