1

我有一个类似 mypage.com/a/b/somePage.html 的页面,其中一个锚点 href 属性类似于“a/b/anotherPage.html”。

当我尝试通过创建具有页面 url 和 href 值的新 url 对象来获取绝对 url 时,我得到的绝对 url 为 mypage.com/a/b/a/b/anotherPage.html。

这给我带来了问题,但是浏览器如何正确处理这个问题。

任何开箱即用的东西都可以解决这个问题。(我总是可以在代码中添加一个异常来以不同的方式处理这个问题,但我不想这样做。)

4

1 回答 1

3

使用 java.net.URL

URL baseUrl = new URL("http:www.google.com/someFolder/");
URL url = new URL( baseURL , "../test.html");
于 2013-03-05T18:09:23.457 回答