View Full Version : send an array of String in an ajax request and get it in JAVA from the server side
flamant
27 Dec 2010, 5:20 AM
Hi,
I try to send several parameters (the number of parameters may vary) in an ajax request and I don't know how to send them and how to get them in JAVA from the server side.
One solution may be : Is it possible to send an array of String : params: { fieldRefForVisibility: parameters } (where parameters is an array of String) and from the server side get them with the following method : java.lang.String[] getParameterValues(java.lang.String name)
Thank you in advance for your answers
Condor
27 Dec 2010, 5:57 AM
And what is the problem? It already works the way you describe.
flamant
27 Dec 2010, 6:19 AM
Hi condor and thank you for your answer,
Usually, when I send parameters in an ajax request I give the name and the value this way
params: { param1: value1, param2: value2 }
This is OK when I have a determined number of parameters and when I expect only param1 and param2 on the server side
from the server side I get them in JAVA this way
String param1 = request.getParameter("param1");
But in my case I would like to send for example this array ["id1;value1", "id2;value2", "id3;value3", ...., "idn;valuen"]
The problem is that I don't know in advance the number of parameters (that is n) which may vary
and the ids (id1, id2, ...) and values (value1, value2, ...) may change from one request to another
So is it possible to send the params this way :
params: { record: ["id1;value1", "id2;value2", "id3;value3", ...., "idn;valuen"] }
And may be get the array in JAVA with the following method : java.lang.String[] getParameterValues(java.lang.String name)
Condor
27 Dec 2010, 6:30 AM
params: {
myParams: ["id1;value1", "id2;value2", "id3;value3", ...., "idn;valuen"]
}
String[] myParams = request.getParameterValues("myParams");
flamant
27 Dec 2010, 6:31 AM
Thank you very much condor.
That is what I was looking for
cheliyan
24 Feb 2017, 8:43 PM
params: {
myParams: ["id1;value1", "id2;value2", "id3;value3", ...., "idn;valuen"]
}
String[] myParams = request.getParameterValues("myParams");
When i use this the array value being like this in servlet page. [Ljava.lang.String;@6ba98755
Please suggest me.
Powered by vBulletin® Version 4.2.3 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.