~/ learn/ comp-348/ cards/ URLs, URIs, and URLConnection
1 of 29

Resolve the four relative references from the worked example against one base URI

Resolve the four relative references from the worked example against one base URI

Answer

URI base = URI.create("http://data.example.org:8080/comp348/week3.html?topic=urls#refs"); System.out.println(base.resolve("week4.html")); System.out.println(base.resolve("notes/lab.html")); System.out.println(base.resolve("/about/")); System.out.println(base.resolve("../images/logo.png"));

One method implements the whole of RFC 3986 resolution: the last path segment is dropped before merging, a leading slash discards the path but keeps the authority, and `..` is normalised away. Every line prints port 8080 — resolution never touches the authority, which is exactly the property string concatenation cannot give you.

Harold 4e ch5 §URIs; §URLs; §Relative URLs

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/71324384-7126-4b0c-8d72-7da21336b971/flashcard utf-8 LF