Possible Duplicate:
How to convert map to url query string?
How to convert Map to query string?
For example:
MockHttpServletRequest request = getRequest();
HashMap<String, String> queryString = new HashMap<String, String>();
queryString.put("IDcontent", "4546446");
queryString.put("ID_CP", "604204d6-3ded-4882-9427-52f1ff8ee6c8");
request.setQueryString(mapToQueryString(queryString));
I think that is this(mapToQueryString) to do standart library, but I can't find it.
You can define a method mapToueryString by yourself as:
StringBuilder sb = new StringBuilder();
for(HashMap.Entry<String, String> e : queryString.entrySet()){
if(sb.length() > 0){
sb.append('&');
}
sb.append(URLEncoder.encode(e.getKey(), "UTF-8")).append('=').append(URLEncoder.encode(e.getValue(), "UTF-8"));
}
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