Esempio n. 1
29
 /** Check if an URL is relative to another URL. */
 public static boolean relativeURL(URL url1, URL url2) {
   return ((url1.getProtocol() == null && url2.getProtocol() == null)
           || url1.getProtocol().equals(url2.getProtocol()))
       && ((url1.getAuthority() == null && url2.getAuthority() == null)
           || url1.getAuthority().equals(url2.getAuthority()))
       && ((url1.getPath() == null && url2.getPath() == null)
           || url2.getPath().startsWith(url1.getPath()));
 }
Esempio n. 2
0
 public static void main(String[] args) throws IOException {
   URL url = new URL("http://www.javajeff.com/articles/articles/html");
   System.out.println("Authority = " + url.getAuthority());
   System.out.println("Default port = " + url.getDefaultPort());
   System.out.println("File = " + url.getFile());
   System.out.println("Host = " + url.getHost());
   System.out.println("Path = " + url.getPath());
   System.out.println("Port = " + url.getPort());
   System.out.println("Protocol = " + url.getProtocol());
   System.out.println("Query = " + url.getQuery());
   System.out.println("Ref = " + url.getRef());
   System.out.println("User Info = " + url.getUserInfo());
 }