Skip to content

Instantly share code, notes, and snippets.

@shaobin0604
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save shaobin0604/9409208 to your computer and use it in GitHub Desktop.

Select an option

Save shaobin0604/9409208 to your computer and use it in GitHub Desktop.
relative url resolve
def resolve(String currentUrl, String redirectUrl) {
URI newUri = new URI(redirectUrl);
if (newUri.isAbsolute()) {
return newUri.toString();
} else {
URI currentUri = new URI(currentUrl);
return currentUri.resolve(newUri);
}
}
println resolve("http://www.baidu.com/", "http://www.sina.com.cn/");
println resolve("http://www.sina.com/xx/aa.jpg", "/login.php");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment