NOTE: I am asking for real world problem, not for theoretical purpose; see the last part of the question -- the same way browsers do the job.
Usually you would see the answer:
new java.net.URL(new java.net.URL(base_url),rel_url).toString (base_url and rel_url are String). In my case base_url is the URL of page I fetched, rel_url comes from "<a href=..." value, so it might be even single "#" character (for example).
However such code does not work for URL fragments, like such two pieces:
htpp://www.hello.com/1.html
?p=2
I tested Firefox, Chromium, Opera, Konqueror, "Web Browser" (Gnome modesty ;-D) -- all of them combine those URLs as:
htpp://www.hello.com/1.html?p=2
With code as above I get:
htpp://www.hello.com/?p=2
Question
How do you combine URL fragments, in a ready for world manner?
I hope there is already handy library for that, before I start doing parsing by myself ;-).
rel_urlstarts with../??p=2isn't a URL.