The situation is as follows:
page.jsp?var[0]=foo&var[1]=bar
How can this be retrieved in an array in Java?
The following:
page.jsp?var=foo&var=bar
I know can be retrieved using request.getParameterValues("var")
Any solutions for the above though?
Map<Integer,String> index2value=new HashMap<Integer,String>();
for (Enumeration e = request.getParameterNames(); e.hasMoreElements() ;)
{
String param= e.nextElement().toString();
if(!param.matches("var\[[0-9]+\]")) continue;
int index= (here extract the numerical value....)
index2value.put(index,request.getParameter(param));
}
Hope this helps.
HashMap m = request.getParameterMap();
Set k = m.keySet();
Set v = m.entrySet();
Object o[] = m.entrySet().toArray();
That will get you a Map call m with K,V pairs and both a set of keys and set of values. You can iterate those sets almost like an array. You can also use toArray to turn it into an array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With