I am looking for a java library/class to parse clean URL's and get all the properties like query, port, host , domain, subdomain etc. Essentially most of the functionality that java.net.URI does but even for clean URLs. I am guessing since this is a pretty common requirement, there might be some libraries already built to handle this. Help?
Asked
Active
Viewed 1,787 times
2 Answers
4
java.net.URL
class has methods getHost()
, getPort()
, getQuery()
, getPath()
.
You can also look at URI
class, it's more preferred to use it.
-
4i would recommend using the URI class since the URL.equals() method actually needs a live connection and does a DNS lookup every time the equals() method is called. so it could be hell for testing in a non networked environment. cher ck here: http://brian.pontarelli.com/2006/12/05/mr-gosling-why-did-you-make-url-equals-suck/ – fasseg Feb 19 '10 at 12:38
-
Nice suggestion. I also watched Josh Bloch presentation on youtube about it but didn't add it to my answer 'cause it's especially matters when URL/URI objects are elements of Set or keys in Map, and it's not the case imho. – Roman Feb 19 '10 at 12:52
-
I am currently using java.net.URL but it doesn't work all that well with Clean URL's. Are there anythings targeted specifically at clean URL libraries? – Ritesh M Nayak Feb 22 '10 at 04:55
-
I'd suggest you to use regular expressions for further parsing. You need one to get list of subdomains, maybe one more to get domain name. Don't know what else you can get from url (if you don't want to implement some tricky logic of course). – Roman Feb 22 '10 at 07:39
0
The standard Java Url classes do not have functionality to parse request parameters. There is a utility class in Commons HTTP Client which has a useful method to do this.

Kees van Dieren
- 1,232
- 11
- 15