views:

74

answers:

1

Is there Apache utility that takes Query String and some encoding and return Map of key,value[] url decoded?

+1  A: 

It's deprecated, but you can use HttpUtils.parseQueryString.

It maps parameter names to values. If the parameter appears more than once, the value is an array.

EDIT: The above method is deprecated because it doesn't allow you to specify character encoding.

The HttpClient project at apache has the classes you need to achieve this.

Use URIUtil.decode(String data, String encoding) to decode the query string.

Then ParameterParser.parse(String query, char separator) to get a list of NameValuePairs. You can then put these into a Commons Collections MultiMap, keyed by parameter name. (You could use a regular hash map, but that involves more code to handle multiple values per key.)

mdma
what about http://www.docjar.com/docs/api/org/apache/catalina/util/RequestUtil.html#parseParameters%28Map,%20byte,%20String%29?
Mohammed
yes, that's what I meant to write! :)
mdma
But, I didn't my app to depend on tomcat libs, Is it exposed else where?
Mohammed
My original suggestion doesn't use tomcat libs. It uses HttpClient and Commons Collections, both apache libraries.
mdma