[英]Sending Map<String,List<String>> as request parameter through ajax
i want to send a Map through ajax request but i am getting 400 bad request. 我想通过ajax请求发送地图,但我收到400错误请求。 My data is like. 我的数据就像。
var idss1 = [];
var idss2 = [];
var idss3 = [];
var idss4 = [];
var idss5 = [];
map[id_1] = idss1;
map[id_2] = idss2;
map[id_3] = idss3;
map[id_4] = idss4;
map[id_5] = idss5;
wehre all the keys (id_*) are string 我们所有的键(id_ *)是字符串
Ajax call is Ajax呼叫是
$.ajax({
type:"POST",
url: myurl,
dataType: "text",
data : {allIds : map},
success: function(response) {...}
at server side my method signature is 在服务器端,我的方法签名是
public void myMethod(HttpServletRequest request, @RequestParam("allIds") Map<String, List<String>> ids) {
...
}
Kindly help me, i shall be thankful. 请帮助我,我将感激不尽。
1) You should never have variables names in a program whose only difference is a number. 1)程序中绝对不能有变量名称,变量名称的唯一区别是数字。 That is what arrays are for. 那就是数组的目的。 The names of the elements in the array are myArr[0], myArr[1], etc. 数组中元素的名称为myArr [0],myArr [1]等。
2) In java, you can do what's called 'serializing' an object. 2)在Java中,您可以执行“序列化”对象的操作。 Serializing converts an object to a string, and a string can be sent in an ajax request, and then the string can be unserialized in your servlet to create an object from the string. 序列化将对象转换为字符串,然后可以在ajax请求中发送字符串,然后可以在servlet中对字符串进行反序列化以从该字符串创建对象。
Serialization to String: How to binary (de)serialize object into/form string? 序列化为字符串: 如何将对象二进制化(反)序列化成字符串/形成字符串?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.