我知道这似乎是一个愚蠢的问题,但我无法找到有关这个问题的任何信息.我有一个java Web服务(使用NetBeans生成),在Web服务类中,我想知道部署Web服务的URL.例如,如果我在本地glassFish服务器上部署Web服务,则Web服务位于"http:// localhost:8080/MyService /",其中"MyService"是我的服务名称.我需要知道此URL的原因是因为我的Web服务生成了一些我需要在此URL上提供的文件.例如,Web服务调用返回URL"http:// localhost:8080/MyService/report.html"我找到了一些关于"WebServiceContext"的链接,但是我无法获取运行我的Web服务的URL .
编辑
澄清一下:在MyWebService.java类中,我想找出部署我的Web服务的URL(在这种情况下,我的Web服务运行在"http:// localhost:8080/MyService /",但是一旦它是部署在生产服务器上,此URL将更改)
小智 8
在我看来更容易,例如:
@GET
public URI redirectSendMail(@Context UriInfo ui) {
return ui.getBaseUri();
}
Run Code Online (Sandbox Code Playgroud)
如果我们想将一个String发送回客户端,指出某些资源的确切路径,我们可能想要这样的东西.
@GET
public String getResourcePath(@Context UriInfo ui) {
return ui.getAbsolutePath();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
76328 次 |
| 最近记录: |