Online Java Compiler By
JavaTpoint.com
import java.net.*; public class UrlGetPathExample2{ URL url; String host,protocol,path; int port; public void HttpCallerInfo(URL url) { this.url= url; host = url.getHost(); int p = url.getPort(); String urlPath = url.getPath(); if (urlPath.length() != 0) this.path = urlPath; else { this.path =null; } protocol = url.getProtocol(); System.out.println("Path of url is : "+path); } public static void main(String args[]) throws Exception { UrlGetPathExample2 ga=new UrlGetPathExample2 (); URL url=new URL("https://localhost/notic/note.jsp"); System.out.println("Given URL is : "+url); ga.HttpCallerInfo(url); } }
Output