Java URL Query Build getQuery(Map params, String encode)

Here you can find the source of getQuery(Map params, String encode)

Description

get Query

License

Open Source License

Declaration

public static String getQuery(Map params, String encode) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

import java.util.Iterator;
import java.util.Map;

public class Main {

    public static String getQuery(Map params, String encode) {
        StringBuffer query = new StringBuffer();

        for (Iterator iter = params.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String value = (String) params.get(name);

            try {
                value = URLEncoder.encode(value, encode);
            } catch (UnsupportedEncodingException e) {
            }/*  w  ww. j  ava2 s .  c o m*/

            query.append(name);
            query.append("=");
            query.append(value);
            query.append("&");
        }

        return query.toString();
    }
}

Related

  1. createQueryString(Map options)
  2. createQueryString(Map params)
  3. createQueryString(Map params)
  4. createQueryStringForParameters(Map parameters)
  5. createQueryStringFromMap(Map m, String ampersand, boolean encode)
  6. getQuery(URL theURL)
  7. getQueryFromURL(URL url)
  8. getQueryMap(String query)
  9. getQueryMap(String urlString)