如何使用 JAX-RS 获取服务器的基本 URL?基本上,当程序在本地服务器上时,我想要“http://localhost:8080/..”,当程序在实时服务器上时,我想要“http://www.theSite.com/...”。我正在使用泽西框架。
最佳答案
是的,您可以使用 myUri = uri.getBaseUri();
在这里你如何获得 Uri 对象:
@Path("myresource")
public class MyResource{
@Context
UriInfo uri;
@GET
public String myresponse(){
URI myUri = uri.getBaseUri();
return ...
}
}
UriInfo 将为您提供大量信息。 Check here the javadoc.
关于url - 使用 JAX-RS 获取我的服务器的基本 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7652321/