在返回响应之前获取servlet请求的状态 [英] Get status of servlet request before the response is returned

查看:72
本文介绍了在返回响应之前获取servlet请求的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好,

我正在编写Java Servlet(Struts 2,Tomcat,JSP等),它能够进行一些相当复杂的模拟。这些最多可能需要2分钟才能完成,并将返回结果图表。计算完成的模拟百分比是微不足道的,因为该过程通过重复相同的计算1000次来工作。

I am in the process of writing a Java Servlet (Struts 2, Tomcat, JSP etc) which is capable of doing some fairly complex simulations. These can take up to 2 minutes to complete on the and will return a graph of the results. It is trivial to calculate the percentage of the simulation completed because the process works by repeating the same calculations 1000s of times.

我很想知道是否有人试过使用客户端技术提供完成百分比的任何估计。即,查询servlet处理以获得在整个模拟中的各个点处完成的循环数。然后,这可以在客户端浏览器中显示为条形。

I would be interested to know if anyone has ever tried to use client side technology to provide any estimate of the percentage complete. I.e query the servlet processing to get the number of cycles completed at various point throughout the simulation. This could then be displayed as a bar in the client browser.

任何想法,建议,资源都将非常感激。

Any thoughts, advice, resources would be much appreciated.

谢谢,

Alex

推荐答案

在您的数据库中,有一个表来维护模拟列表及其服务器计算的进度。

In your database, have a table to maintain a list of simulations along with their server-calculated progress.

在您的Web应用程序中,每隔几秒钟使用AJAX查询服务器(1 -20取决于负载是我要去的)并更新图形进度条。大多数javascript库都有简单的基于计时器的AJAX函数来完成这类工作。

In your web-application, use AJAX to query the server every few seconds (1-20 depending on load is what I'd go with) and update a graphical progress bar. Most javascript libraries have simple timer-based AJAX functions to do exactly this sort of thing.

有一些细节需要弄清楚,比如是否有完成的模拟仍然存在DB(可能是有用的日志信息),但总的来说,这应该是相当简单的。

There's a few details to figure out, such as whether or not completed simulations remain in the DB (could be useful logging info), but overall, this should be fairly simple.

这篇关于在返回响应之前获取servlet请求的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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