Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.net.URL;

import java.util.HashMap;
import java.util.Map;

public class Main {
    public static String getQueryValue(String url, String name) {
        try {
            URL dUrl = new URL("http://" + url);
            Map<String, String> query = getQueryMap(dUrl.getQuery());
            return query.get(name);

        } catch (Exception e) {
        }

        return null;
    }

    public static Map<String, String> getQueryMap(String query) {
        String[] params = query.split("&");
        Map<String, String> map = new HashMap<String, String>();
        for (String param : params) {
            String[] splitted = param.split("=");
            map.put(splitted[0], splitted[1]);
        }
        return map;
    }
}