views:

91

answers:

1

Hi All,

I want to append a list in the url that is a href ,how can do so and how can i read it using request.getParameter() ? or a complete bean object in the url ?

+1  A: 

Use the same name for every item, build something like this, http://example.com/somepath?amt=1&amt=2&amt=3.

And then you can use HttpServletRequest.getParameterMap(). Or alternatively, you can use HttpServletRequest.getParameterValues(name). You might like to use the latter by specifying the name, for example,

String[] amts = request.getParameterValues("amt");

By the way, getParameterMap() will give you a Map object having parameter names as key. It will have all other request parameters as well as your 'amt'.

Map map = request.getParameterMap();
String[] amts = map.get("amt");
Adeel Ansari
sarah
HttpServletRequest.getParameterMap() is failing ,i am appending the list in a url .please update the answer
sarah
getParameterMap will give you a Map object having parameter names as key. It will have all other request parameters as well as your 'amt'. So, you might like to go with the latter one.
Adeel Ansari
Adeel Ansari
HashMap map=(HashMap) getRequest().getParameterMap();log.info("key is ::"+map.get("amt").toString());is it some thing like this ?how wil it give me the value ?
sarah
Try this, and please take my advice and make a habit to read the docs. See my addendum.
Adeel Ansari
It returns a `String[]`. By the way, `getParameterValues()` way is preferred.
BalusC
getParameterValues() is returning me a string[] ,i am appending a complete list in the usrl as amt=somelist ,how would i get the complete list using getParameterValues("amt") ?please clarify it.
sarah
you must do this: http://example.com/somepath?amt=1 note that the same parameter is appended several times.
KarlP
sarah
sarah
Don't tell me, you can't loop over your list? Its that simple. You even do it in your JSP using JSTL/EL. And doing it in Java is no problem at all.
Adeel Ansari