GWT - 如果服务器更新,客户端如何检测到它的 javascript 不同步

发布于 2024-12-05 01:16:11 字数 305 浏览 1 评论 0原文

我有一个 GWT 应用程序,用户可以无限期地保持应用程序基于浏览器的一侧打开。我们经常升级应用程序 - 如果用户在完成此操作后在浏览器中点击重新加载,那么一切都会正常。然而,通常发生的情况是,他们继续使用已经打开的应用程序版本,即升级之前提供的版本,然后遇到与 RPC 相关的模糊错误,因为客户端 Javascript 不再与服务器上的同步。

GWT 是否有任何可以启用或合并到代码中的机制来处理此问题。我不需要对这种情况进行任何巧妙的处理,例如尝试重新加载应用程序并重新建立用户的当前状态,一个简单的对话框解释客户端和服务器不再同步并且需要重新加载 Web 应用程序就足够了。

I have a GWT application where users keep the browser based side of the application open indefinitely. Every so often we upgrade the application - if the users hit reload in their browsers after this is done then everything goes fine. However what usually happens is that they carry on using the already open version of the application, i.e. a version served before the upgrade, and then experience obscure RPC related errors as the client side Javascript is no longer in sync with what is on the server.

Does GWT have any mechanism, that you can enable or incorporate in your code, for coping with this. I don't need any clever handling of the situation, e.g. trying to reload the application and reestablish the user's current state, a simple dialog explaining that client and server are no longer in sync and that the web application needs to be reloaded would be enough.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灯下孤影 2024-12-12 01:16:11

接口文档 com.google.gwt.user.client.rpc.AsyncCallback给出了如何执行此操作的提示。

   public void onFailure(Throwable caught) {
     // Convenient way to find out which exception was thrown.
     try {
       throw caught;
     } catch (IncompatibleRemoteServiceException e) {
       // this client is not compatible with the server; cleanup and refresh the 
       // browser
     } catch (InvocationException e) {
       // the call didn't complete cleanly
     } catch (ShapeException e) {
       // one of the 'throws' from the original method
     } catch (DbException e) {
       // one of the 'throws' from the original method
     } catch (Throwable e) {
       // last resort -- a very unexpected exception
     }
   }

您很可能想要处理(弹出用户对话框)IncompleteRemoteServiceException

The documentation of the interface com.google.gwt.user.client.rpc.AsyncCallback<T> gives a hint on how to do this.

   public void onFailure(Throwable caught) {
     // Convenient way to find out which exception was thrown.
     try {
       throw caught;
     } catch (IncompatibleRemoteServiceException e) {
       // this client is not compatible with the server; cleanup and refresh the 
       // browser
     } catch (InvocationException e) {
       // the call didn't complete cleanly
     } catch (ShapeException e) {
       // one of the 'throws' from the original method
     } catch (DbException e) {
       // one of the 'throws' from the original method
     } catch (Throwable e) {
       // last resort -- a very unexpected exception
     }
   }

You most likely want to handle (pop-up the user dialog) the IncompatibleRemoteServiceException.

书信已泛黄 2024-12-12 01:16:11

它称为 IncompleteRemoteServiceException,以及如何处理包括此在内的异常,在Google的与服务器通信文档。

It is called IncompatibleRemoteServiceException, and how to handle exceptions including this one is mentioned in the Google's Communicating with a Server Documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文