Building an absolute URL from a relative URL in Java

后端 未结 4 1682
一向
一向 2020-12-03 14:35

I\'m having trouble building an absolute URL from a relative URL without resorting to String hackery...

Given

http://localhost:8080/myWebApp/someSer         


        
4条回答
  •  情深已故
    2020-12-03 14:53

    How about:

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

提交回复
热议问题