[ACCEPTED]-Building an absolute URL from a relative URL in Java-relative-url

Accepted answer
Score: 43

Using java.net.URL

 URL baseUrl = new URL("http://www.google.com/someFolder/");
 URL url = new URL(baseUrl, "../test.html");

0

Score: 4

How about:

String s = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/someImage.jpg";

0

Score: 1

Looks like you already figured out the hard 3 part, which is what host your are running 2 on. The rest is easy,

String url = host + request.getContextPath() + "/someImage.jpg";

Should give you what 1 you need.

More Related questions