如何从一个 Eclipse RAP 入口点访问另一个入口点?

How can I access one Eclipse RAP entry point from another?

我有一个带有两个入口点的 Eclipse RAP 2.3 应用程序,比如 /first/second。 在第一个入口点的 GUI 中,有一个按钮,我想用它在新的浏览器选项卡中打开第二个入口点。该按钮的事件处理程序当前为

UrlLauncher launcher = RWT.getClient().getService( UrlLauncher.class );
launcher.openURL( "/second");

当应用程序在 Tomcat 网络服务器中部署为 myapp.war 时,这已经不起作用(然后应该是 /myapp/second)。

我的问题:


更新

根据 Rüdiger 的评论,我可以通过两种不同的方式获取上下文路径。

  1. 第一种方法是

    RWT.getRequest().getContextPath();
    

    其中 RWT.getRequest() is documented with

    This method is not recommended

  2. 其次,我可以通过

    获得
    ApplicationContextImpl ac = (ApplicationContextImpl) RWT.getApplicationContext();
    String contextPath = ac.getServletContext().getContextPath();
    

    IDE 显示警告的地方

    Discouraged access: The type ApplicationContextImpl is not accessible due to restriction on required library ...\org.eclipse.rap.rwt_2.3.2.20150128-1013.jar

    尽管有警告,但在将带有 OSGi 捆绑包的 WAR 文件部署到 Tomcat 时它仍然有效。

因此,在这两种情况下都有某种警告,这使得解决方案看起来更像是解决方法。

不推荐使用 RWT.getRequest(),因为通常 RWT 会使您免受较低级别的 servlet API 的影响,并且与请求的某些直接交互甚至可能会干扰 RWT 的生命周期并产生有趣的响应。

虽然在您的情况下通过 RWT.getRequest() 访问 ServletContext 是安全的,但我建议使用

RWT.getUISession( display ).getHttpSession().getServletContext();

访问 servlet 上下文。

第二种方法访问不属于 public API 的内部 类,因此不应使用。访问的 类 将来可能会更改或(重新)移动,恕不另行通知并破坏您的应用程序。