简体   繁体   English

如何将数据从输入类型=“文件”发送到控制器?

[英]How can I send the data from a imput type=“file” to the controller?

I have in the ftl: 我在ftl中:

<input type="file" id="doc6" name="documente">

in .js: 在.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);
        }

and in the controller: 并在控制器中:

@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){
.....
}

but doc6 is not what I need when I read it like that and the error is: 但是当我这样阅读时,doc6不是我所需要的,并且错误是:

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

can you tell me how should I read the data from file? 您能告诉我如何从文件中读取数据吗? clearly var doc6 = $('doc6').val(); 显然var doc6 = $('doc6').val(); it's not ok. 不好

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

headers = "content-type=multipart/*"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FXML 文件中的 For 循环 || 如何将数据从 controller 发送到 fxml 文件? - For loop in FXML file || How to send data from controller to fxml file? 如何在Spring,JSP中将表单值从jsp文件发送到控制器? - How can I send form values from jsp file to controller in Spring, JSP? 如何从 html 文件向控制器发送对象或数据? - How to send object or data to controller from html file? 如何在Spring中将数据从Controller发送到JSP页面? - How do I send data from a Controller to a JSP page in Spring? 如何将值数组从输入发送到控制器 - How can I send an array of values from the inputs to the controller 如何将对象从控制器发送到视图Spring MVC - How can I send an object from a controller to a view Spring MVC 如何将参数从过滤器发送到控制器? - How can I send a parameter from a filter to a controller? 如何根据文件中的数据类型从CSV文件读取2个ArrayList? - How can I read from a CSV file into 2 ArrayLists depending on the data type I have got in the File? 如何将数据从Ajax发送到Spring Controller - How to send data from ajax to spring controller 将文件从JSP发送到调用接口方法的控制器-如何从该请求上传文件? - Send a file from JSP to controller which calls a method of interface -How do I upload a file from that request?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM