Hello i have an url in my jsp and i want to pass an array of string in this url to recover in my ActionForm
-
1So, do you have Java array or JavaScript array? – Nikita Rybak Oct 18 '10 at 13:27
-
i have a seven checkbox and when i click in my url i want to pass what box is checked – Mercer Oct 18 '10 at 13:29
-
serialization Or json encode ! – zod Oct 18 '10 at 13:30
-
would you have a simple example – Mercer Oct 18 '10 at 13:31
-
http://code.google.com/p/json-simple/wiki/EncodingExamples#Example_5-1_-_Combination_of_JSON_primitives,_JSON_object_and_JS am not a java guy . but am using json encode in php . but this example is for java. If these are tough for you concatinate those array parameters and make it a string and pass. :) – zod Oct 18 '10 at 13:49
-
Just remember that URLs have a limit, so I hope you are not trying to carry to much data in the query string. – epascarello Oct 18 '10 at 13:54
3 Answers
If you are dealing with something simple like a list of numeric ids, i would just run through the check boxes, create a comma separated list, and assign it to a query string parameter. On the other side i would split the string. If the values are more complex you have to consider escape characters. Also if you are dealing with a long list, the url is not the best way to pass this data.

- 1,247
- 11
- 30
You can use 'standard' html way of passing arrays of data: http://mywebsite/mypage?myarray=value1&myarray=value2&myarray=value3
. Then you can fetch all values of parameter myarray
from request object (if framework doesn't provide more elegant ways of handling arrays).
But seeing your comment, I would recommend to leave JavaScript and just declare a form for it.
If you need a link (not button), you can always submit form from it. Something like <a href="javascript:$('#myForm').submit();">...</a>

- 67,365
- 22
- 157
- 181