Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Incoming Parameter is an array, req.getParameter returns String, help!

843841Jun 20 2003 — edited Jun 20 2003
Hello,
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&param1[]=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.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 18 2003
Added on Jun 20 2003
3 comments
1,121 views