java: decoding URI query string
Posted
by Jason S
on Stack Overflow
See other posts from Stack Overflow
or by Jason S
Published on 2010-04-13T18:34:48Z
Indexed on
2010/04/13
18:43 UTC
Read the original article
Hit count: 442
I need to decode a URI that contains a query string; expected input/output behavior is something like the following:
abstract class URIParser
{
/** example input:
* something?alias=pos&FirstName=Foo+A%26B%3DC&LastName=Bar */
URIParser(String input) { ... }
/** should return "something" for the example input */
public String getPath();
/** should return a map
* {alias: "pos", FirstName: "Foo+A&B=C", LastName: "Bar"} */
public Map<String,String> getQuery();
}
I've tried using java.net.URI, but it seems to decode the query string so in the above example I'm left with "alias=pos&FirstName=Foo+A&B=C&LastName=Bar" so there is ambiguity whether a "&" is a query separator or is a character in a query component.
edit: just tried URI.getRawQuery() and it doesn't do the encoding, so I can split the query string with a "&", but then what do I do?
Any suggestions?
© Stack Overflow or respective owner