Here you can find the source of getAbsoluteURL(String baseURLString, String relURlString)
public static final String getAbsoluteURL(String baseURLString, String relURlString)
//package com.java2s; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; public class Main { /** */// w w w . j a v a 2 s.c o m public static final String getAbsoluteURL(String baseURLString, String relURlString) { try { URL baseURL = new URL(baseURLString); String url = baseURL.getProtocol() + "://" + baseURL.getHost() + ":" + baseURL.getPort() + toRelativeURL(relURlString); return url; } catch (IOException e) { return ""; } } /** */ public static final String toRelativeURL(String urlString, boolean withParam) { String uri = null; try { URL url = new URL(urlString); uri = url.getPath(); if (withParam == true) { String queryString = url.getQuery(); if (!queryString.equals("")) { uri += ("?" + queryString); } } if (uri.endsWith("/")) { uri = uri.substring(0, uri.length() - 1); } } catch (MalformedURLException e) { if (urlString == null) { uri = ""; } else if (0 < urlString.length() && urlString.charAt(0) != '/') { uri = "/" + urlString; } else { uri = urlString; } } return uri; } /** */ public static final String toRelativeURL(String urlString) { return toRelativeURL(urlString, true); } }