Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    /**
     * Return the base URL from the given URL.  Example:
     * http://foo.org/abc.html -> http://foo.org/
     * @param surl
     * @return The base URL.
     */
    public static String getBaseUrl(String surl) {
        URL url;
        try {
            url = new URL(surl);
            System.out.println("getHost: " + url.getHost());
            return "http://" + url.getHost() + "/";
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return null;
    }
}