Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL parsing in Java

I've got the URL like this:

http://test.com/testapp/test.do?test_id=1&test_name=SS

Is there any way we can get only this part

/test.do?test_id=1&test_name=SS

like image 425
user2346047 Avatar asked Feb 04 '14 06:02

user2346047


People also ask

What is URL parsing?

URL Parsing. The URL parsing functions focus on splitting a URL string into its components, or on combining URL components into a URL string.

What is the data type of URL in Java?

URL(String protocol, String host, int port, String file, URLStreamHandler handler):

What are the URL parse module method?

The url. parse() method takes a URL string, parses it, and it will return a URL object with each part of the address as properties. Parameters: This method accepts three parameters as mentioned above and described below: urlString: It holds the URL string which needs to parse.


1 Answers

Use java.net.URL to parse a url string:

URL url = new URL("http://test.com/testapp/test.do?test_id=1&test_name=SS");
System.out.println(url.getPath()+"?"+url.getQuery());
like image 165
sadhu Avatar answered Oct 12 '22 00:10

sadhu