How to pass javascript arrays to ajax send() method and retrieve them on jsp page ?

I have following html page:
Here I have passed url to ajax's send method and retrieved those values on jsp page.
How to pass multiple arrays instead of url to send() method, and how to retrieve those arrays on jsp ?
The code is from Expert rrz.

The html page :
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<script type="text/javascript">
function ajaxFunction(){
	var ajaxRequest; 
	var parameters="product=Mobile&location=India&year=2014 ";
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
				alert("Error!!");
				return false;
			}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
                if (ajaxRequest.status === 200) {
                } else {
                        alert('Error: ' + ajaxRequest.status); 
                       }
			    //document.myForm.result.value = ajaxRequest.responseText;
				document.getElementById("result").value = ajaxRequest.responseText;
	    }
	}
	ajaxRequest.open("POST", "rrz_ajax.jsp", true);
	ajaxRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	ajaxRequest.send(parameters); 
}
</script>
</head>
<body>
Click on Send button.<br/>
<input type='button' onclick="ajaxFunction();" value="Send" /><br/>
Result from server: <input type='text' id='result' size="100"/>
</body>
</html>
                                      

Open in new window


The jsp page :
<%
String product = request.getParameter("product");
String location = request.getParameter("location");
String year = request.getParameter("year");
%>

Open in new window

Pradip ShenolkarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pradip ShenolkarAuthor Commented:
I found solution :

html page
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<script type="text/javascript">

function ajaxFunction(){
	var ajaxRequest; 
	var parameters="product=Mobile&location=India&year=2014 ";
	var pr=["mobile","tv","laptop"];
	var prs=["2010","2013"];
	var products="products="+pr+"&time="+prs;
//	
	
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
				alert("Error!!");
				return false;
			}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
                if (ajaxRequest.status === 200) {
                } else {
                        alert('Error: ' + ajaxRequest.status); 
                       }
			    //document.myForm.result.value = ajaxRequest.responseText;
				document.getElementById("result").value = ajaxRequest.responseText;
	    }
	}
	ajaxRequest.open("POST", "rrz_ajax.jsp", true);
	ajaxRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	ajaxRequest.send(products); 
}
</script>
</head>
<body>
Click on Send button.<br/>
<input type='button' onclick="ajaxFunction();" value="Send" /><br/>
Result from server: <input type='text' id='result' size="100"/>

</body>
</html>
                      

Open in new window


jsp page:
<%@ page import="mypkg.TestPost" %>
<%
String[] products=request.getParameterValues("products");
String[] time=request.getParameterValues("time");
%>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.