如何获得Vaadin 7应用服务器的IP和端口?

Jor*_*rio 9 java vaadin7

如何获取运行我的Vaadin webapp的应用服务器的协议,IP和端口?我正在使用Vaadin 7.

在vaadin 6中我这样做,但不能在vaadin 7中工作:

String server = ((WebApplicationContext) this.getContext()).getHttpSession().getServletContext().getServerInfo();

java.net.URL url = this.getURL();
String s = url.getHost()+":"+url.getPort()+url.getPath();
Run Code Online (Sandbox Code Playgroud)

小智 14

System.out.println(UI.getCurrent().getPage().getLocation().getHost());
System.out.println(UI.getCurrent().getPage().getLocation().getPath());
System.out.println(UI.getCurrent().getPage().getLocation().getPort());
Run Code Online (Sandbox Code Playgroud)


小智 7

我是这样做的:

String basePath = Page.getCurrent().getLocation().getScheme() + ":" +
                  Page.getCurrent().getLocation().getSchemeSpecificPart()
Run Code Online (Sandbox Code Playgroud)