Is there a Java package to handle building URLs? -


I'm specifically looking for some code in Java which takes the Map object And convert it to a query string that I can add to the returning URL. I'm sure there is a library that does it more, but I can not find it with Google Search faster than anyone Know what this will do? I found a solid and versatile library to handle HTTP in Java though, there is a sample class here, The URL that can be sufficient for building query string:

  import java.net.URLEncoder; Public class QueryString {Private string query = ""; Public query string (hashmap> string, string> map) {Iterator it = mp.entrySet (). Iterator (); While (this hasNext ()) {map.Entry pairs = (Map.Entry) it.next (); Query + = URLEncoder.encode (pairs.getKey (), "utf-8") + "=" + URLEncoder.encode (pairs.getValue (), "utf-8"); If (it.hasNext ()) {query + = "& amp;"; }}} Public QueryString (object name, object value) {query = URLEncoder.encode (name.toString (), "utf-8") + "=" + URLEncoder.encode (value.toString (), "utf- 8 "); } Public query string () {query = ""; } Public synchronized zero (object name, object value) {if (! Query.trim (). Equals ("")) query + = "& amp;"; Query + = URLEncoder.encode (name.toString (), "utf-8") + "=" + URLEncoder.encode (value.toString (), "utf-8"); } Public string toString () {return query; }}  

Usage:

  hashmop & lt; String, string & gt; Map = new hashmap & lt; String, string & gt; (); Map.put ("Hello", "World"); Map.put ("Lang", "N"); Query string q = new query string (map); Println (q); // = & gt; "Hello = world and gender = n"  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -