Java URL Query Build getQueryFromURL(URL url)

Here you can find the source of getQueryFromURL(URL url)

Description

get Query From URL

License

Open Source License

Declaration

public static Hashtable<String, String> getQueryFromURL(URL url) 

Method Source Code

//package com.java2s;
/*// ww w .jav  a2  s  .  c  o m
  * (c) Copyright 2010-2011 AgileBirds
  *
  * This file is part of OpenFlexo.
  *
  * OpenFlexo is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * OpenFlexo is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with OpenFlexo. If not, see <http://www.gnu.org/licenses/>.
  *
  */

import java.net.URL;
import java.util.Hashtable;
import java.util.StringTokenizer;

public class Main {
    public static Hashtable<String, String> getQueryFromURL(URL url) {
        if (url == null || url.getQuery() == null)
            return new Hashtable<String, String>();
        Hashtable<String, String> returned = new Hashtable<String, String>();
        StringTokenizer st = new StringTokenizer(url.getQuery(), "&");
        while (st.hasMoreTokens()) {
            StringTokenizer subSt = new StringTokenizer(st.nextToken(), "=");
            String key = null, value = null;
            if (subSt.hasMoreTokens())
                key = subSt.nextToken();
            if (subSt.hasMoreTokens())
                value = subSt.nextToken();
            if (key != null && value != null)
                returned.put(key, value);
        }
        return returned;
    }
}

Related

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