【问题标题】:How to get the Vaadin 7 application server IP and port?如何获取 Vaadin 7 应用服务器 IP 和端口?
【发布时间】:2016-04-27 10:04:11
【问题描述】:

如何获取运行我的 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();

【问题讨论】:

    标签: java vaadin7


    【解决方案1】:
    System.out.println(UI.getCurrent().getPage().getLocation().getHost());
    System.out.println(UI.getCurrent().getPage().getLocation().getPath());
    System.out.println(UI.getCurrent().getPage().getLocation().getPort());
    

    【讨论】:

      【解决方案2】:

      我是这样做的:

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 2021-05-09
          • 2010-11-16
          • 2010-12-22
          • 2013-06-09
          • 2015-01-29
          • 2019-07-17
          • 2013-01-12
          • 2011-06-17
          • 1970-01-01
          相关资源
          最近更新 更多