如何长效的HTTP请求工作 [英] How to work with long-lasting http requests

查看:227
本文介绍了如何长效的HTTP请求工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个持久的HTTP请求(很多后端计算)。

I have a long-lasting http request (a lot of computation in the back-end).

目前这一切都同步,而服务器电脑,浏览器不会看到输出/结果。一段时间后,则连接断开,并显示在浏览器中的超时错误。

Currently it's all synchronous, while the server computer, the browser doesn't see the output/result. After a while, the connection is dropped and an timeout error is displayed in the browser.

我想一些信息返回到浏览器马上,并使其等待结果。如何实现这一目标?

I'd like to return some info to the browser right away, and make it wait for the result. How to achieve this?

请注意,该Java后端是同步的。因此,一个解决方案将需要一些的破解的在servlet /前端可能需要JavaScript的请求..?

Please note, that the Java back-end is synchronous. So a solution would require some hack in the servlet/front end possibly requiring javascript requests.. ?

推荐答案

超时不会,只要你写的东西到输出流(它甚至可以是空格,不要忘了打电话occure 冲洗())。

Timeout won't occure as long as you write something to output stream (it can even be spaces, don't forget to call flush()).

这样的长效请求让SENCE当你,例如,打印大型报告,该报告显示给用户以后,因为它是生成的。

Such long-lasting request makes sence when you, for example, print a large report, which is shown to the user subsequently as it is generated.

在所有其他情况下,返回等待页面给用户,并定期使用AJAX请求询问如果处理已完成。当没有什么变化,而浏览器显示加载,这不是一个很好的用户体验。

In all other cases, return the waiting page to the user and use periodical AJAX requests to ask if the processing has finished. When nothing changes and the browser is showing loading, it is not a good user experience.

这篇关于如何长效的HTTP请求工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆