[英]How to receive arrays sent by Ajax in a .jsp file
Hi I wrote the below js code to send two arrays to a jsp file 嗨,我写了下面的js代码,将两个数组发送到jsp文件
$.post("scriptlet.jsp",
{ sg: array1[], st: array2[] },
function(data){
alert("Data Loaded: " + data);
}
);
How do I retrieve them form the jsp side? 如何从jsp端检索它们? I tried doing this inside scriptlet.jsp .
我尝试在scriptlet.jsp中执行此操作。 But didn't work
但没有奏效
<%
String[] questionsList = (String)request.getParameter("sg");
%>
if i understand very well your problem , so you are trying to send JavaScript array to a jsp
page , so here are my suggestion : 如果我非常了解你的问题,所以你试图将JavaScript数组发送到
jsp
页面,所以这是我的建议:
<script >
var tab = ["hello","world"]; //here is an array for test
$.get("scriptlet.jsp",{ sg:tab },function(data){
alert("Data Loaded: " + data);
}
);
</script>
</head>
<body>
<%
String[] myArray = request.getParameterValues("sg[]");
out.println(myArray[0]); // this will print you "hello"
%>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.