如果我有一个java.net.URL对象,指向让我们说
http://example.com/myItems 要么 http://example.com/myItems/
是否有某个帮助器在某处附加一些相对URL?例如追加./myItemId或myItemId得到:
http://example.com/myItems/myItemId
我有一个网址:
URL url=new URL("http://www.abc.com/aa/bb/cc/file.html");
Run Code Online (Sandbox Code Playgroud)
和相对路径:
String relativePath="../file2.html"; //maybe is "/file3.html"
Run Code Online (Sandbox Code Playgroud)
我想要http://www.abc.com/aa/bb/file2.html使用变量url和relativePath
怎么做?
我无法从相对URL构建绝对URL而无需使用String hackery ...
特定
http://localhost:8080/myWebApp/someServlet
Run Code Online (Sandbox Code Playgroud)
方法内部:
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
Run Code Online (Sandbox Code Playgroud)
什么是最"正确"的建设方式:
http://localhost:8080/myWebApp/someImage.jpg
Run Code Online (Sandbox Code Playgroud)
(注意,必须是绝对的,而不是相对的)
目前,我是通过构建字符串来实现的,但必须有更好的方法.
我查看了新URI/URL的各种组合,我最终得到了
http://localhost:8080/someImage.jpg
Run Code Online (Sandbox Code Playgroud)
非常感谢