在请求失败,当网络重新连接浏览器,它的自我决策的请求它的、浏览器、自我、网络

2023-09-10 16:48:02 作者:京昭

我使用GWT(Java中的JavaScript)的前端,而 RPC 机制( AJAX )使服务器请求( Servlet的是关键)。

I'm using GWT (Java to JavaScript) as front-end, and RPC mechanism (AJAX) to make server requests (Servlets are the keys).

一切都顺利进行,截至目前。

Everything going smooth as of now.

现在测试的情况下,已经产生像

Now a test-case has been generated like

1)发出请求到服务器

1)Make a request to server

客户端(用户)2)在断开的网络连接。

2)In between disconnect the internet of client (user).

3)我们正在处理的 InvocationException 通过展示一些的消息

3)We are handling that InvocationException by showing some message.

 @Override
    public void onFailure(Throwable caught) {
        NTMaskAlert.unMask();
        if(caught instanceof InvocationException){  
         NTFailureMessage.showFailureException(caught,"Network disconnected");
         }
        onNTFailure(caught);
    }

3)现在客户端重新连接,用户制作的要求。

3)Now client reconnected, user making a request.

下面是有趣的观点。

一旦网络重新连接,浏览器开始处理previous 要求,我在火错误观察到这一点。如果我断开两次,两次重新连接,自动请求去两次,数据发生重复。

As soon as the internet reconnected, the browser started processing the previous request, I observed this in fire-bug. If I disconnect twice and reconnected twice, automatically request going twice and duplication of data happening.

推荐答案

原因很简单,这种行为是典型的用户想要的。

The reason for is simply that this behaviour is typically what users want.

即,如果它们是暂时关闭的网络,例如因为无线路由器已关闭,则大部分的他们预计的时间,即浏览器,邮件,等等,将尝试重新连接时,网络又回来了,它们不要指望得去每一个窗口和刷新让它重新开始工作。

That is, if they are temporarily off of the network, for example because the wireless router is down, then most of the time they expect that the browser, mail, etc, will attempt to reconnect when the network is back, they don't expect to have to go to every window and "refresh" to get it to start working again.