Last active
August 29, 2015 13:57
-
-
Save shaobin0604/9409208 to your computer and use it in GitHub Desktop.
relative url resolve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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