Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the path of a URL

Tags:

Have a URL, how to retrieve its path part?

http://www.costo.com/test1/test2

How to get "test1/test2"

like image 916
user496949 Avatar asked Apr 06 '11 10:04

user496949


People also ask

What is URL path example?

Most servers use the well-known port numbers for HTTP and HTTPS , so most HTTP URLs omit the port number. A path. The path identifies the specific resource in the host that the web client wants to access. For example, /software/htp/cics/index.

How do you split a URL?

var newURL="http://www.example.com/index.html/homePage/aboutus/"; console. log(newURL); var splitURL=newURL. toString(). split("/"); console.


1 Answers

You want something like this:

String path = new URL("http://www.costo.com/test1/test2").getPath(); 

Actually that'll give you /test1/test2. You'll just have to remove the first / to get what you want:

path = path.replaceFirst("/", ""); 

Now you'll have test1/test2 in path.

like image 112
WhiteFang34 Avatar answered Sep 23 '22 18:09

WhiteFang34