从网址获取域名
/** nowjava.com - 时代Java **/ //package com.nowjava; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; public class Main { public static String getDomainFromUrl(String url) { if (url == null || !isValidUrl(url)) return ""; return url.split("//")[1].split("/")[0]; } public static boolean isValidUrl(String url) { if (url == null || url.length() == 0) return false; /* *来 自 时代Java */ /* * from stackoverflow: * http://stackoverflow.com/questions/1600291/validating-url-in-java */ URL u = null; try { u = new URL(url); } catch (MalformedURLException e) { return false;