Incoming Parameter is an array, req.getParameter returns String, help!
843841Jun 20 2003 — edited Jun 20 2003Hello,
I commonly use parameter arrays in my HTML forms. Meaning I have 1 name associated with mulitple values, such as
param1[] = "somevalue"
param1[] = "anotherval".
Which would look like, in a GET request,
http://mydomain/servlet?param1[]=somevalue¶m1[]=anotherval
(this URL would encode the [ and ] in the browser)
My problem is that request.getParameter() returns a string only. I want it to return a string sometimes, and an array other times!
From the docs:
public java.lang.String getParameter(java.lang.String name)
I want a public java.lang.Array getParameterArray(java.lang.String name)
Why isnt there one?! :-( I use it all the time for dynamic things in forms, like say, attributes on a product's page. Some products have no attributes (red, yellow, large, etc) and some have hundreds! So I'd want to have, say,
attribute[] = red
attribute[] = large
and have my code be able to just run through the array, like, pseudo:
foreach element in attribute[]{
save attribute to product in persons cart
}
Any help would be appreciated. And please dont say getQueryString and parse it yourself! i dont wanna.