开发者

Keeping a web request alive

开发者 https://www.devze.com 2022-12-27 15:50 出处:网络
I have a web application , that helps download reports. But the report generation sometimes takes a lot of time, and the web request times out through the intermediate proxy server.(Timeout :90 secs).

I have a web application , that helps download reports. But the report generation sometimes takes a lot of time, and the web request times out through the intermediate proxy server.(Timeout :90 secs). The workflow for downloading the report is straightforward. Client sends request to the web server. The web server generates the report , and makes it available to the client as an excel download.

The excel is generated using POI and the download is provided using Spring's AbstractExcelView.

What could be the best way to ke开发者_如何学JAVAep the web request alive(without increasing the timeout , of course) ?


One way is to make the initial request return a holding screen saying, "We're generating the report..." including a request token and JavaScript (typically AJAX) to pass that request token back to the web application periodically to see if the report is done, and display it when it is.

If you have any indication within the web app code of how far the report has got, that progress can be communicated back through the AJAX too.

That way each request is answered in a reasonably short period, but the report generation "session" is kept alive by the token ID. When the report is finished on the server you'd probably want to store it in a cache somewhere until it's requested - and expire it after a while, in case the browser has been closed.

Oh, and a nice side effect I didn't mention before - the user gets to see that the web app is still alive, and they've still got a network connection to it. Leaving a cursor spinning for a couple of minutes can be unnerving :)


Have you tried using a COMET enabled server ? You can keep a long running request alive by using a variety of techniques like COMET or even long polling. Or a simple AJAX alive ping to the server should do the trick. Reload the page using Ajax when you know that the report has been generated.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号