繁体   English   中英

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

[英]How to get the Vaadin 7 application server IP and port?

如何获取运行我的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();
System.out.println(UI.getCurrent().getPage().getLocation().getHost());
System.out.println(UI.getCurrent().getPage().getLocation().getPath());
System.out.println(UI.getCurrent().getPage().getLocation().getPort());

我是这样做的:

String basePath = Page.getCurrent().getLocation().getScheme() + ":" +
                  Page.getCurrent().getLocation().getSchemeSpecificPart()

至于应用程序路径部分,要获取真正的应用程序目录而不是浏览器请求路径,请使用VaadinServlet.getCurrent().getServletContext().getContextPath()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM