I have a list box in an HTML form. I want to send the list items to a servlet using jquery and AJAX. At the server side, I want to add the sent list items one by one in a database. I tried this using an array in my jsp where I filled it with list items,and then sent it using AJAX, but at servlet I am getting NULL.
my jsp code:
var arr=new Array();
var rel=$("#rcombo :selected").text();
$("#listbox option").each(function(){
arr[0]=$("#listbox").text();
});
$.ajax({
type:"get",
url:"NewServlet",
data:{list:arr,rel:rel},
success:function(){}
});
servlet code:
String list[]=request.getParameterValues("list");
System.out.println(list);
Then I changed the code a little bit:
jsp:
var arr=new Array();
var rel=$("#rcombo :selected").text();
$("#listbox option").each(function(){
arr[0]=$("#listbox").text();
});
$.ajax({
type:"get",
url:"NewServlet",
data:{list:arr[0],rel:rel},
success:function(){}
});
servlet:
String list[]=request.getParameterValues("list");
System.out.println(list[0]);
Now, I am getting the data. But, all items are in list[0]. I am not able to extract them one by one. Please help me.