Status of the process triggered by request in java

女生的网名这么多〃 提交于 2019-12-25 05:06:14

问题


Is it possible to get the status of the process triggered by a request.

Suppose, I have a request, that will trigger the long running process, like copying some files in the server side, or some other really long running process. Now I want to show user about the percentage completion of that task.

How to do it in Java Servlet, or any other frame which supports this?

What I thought was sending the continous response to the page. But this may not be possible. Please help me with this problem.

Thanks.


回答1:


One solution is to create another servlet that provides the percentage as json (you may store it in a session object), then with javascript periodically poll informations from this servlet and show them directly.

This post might help you:

JQuery Get JSON from servlet




回答2:


You can follow the above shown model. There are two servlets one for starting the processing and another reporting the status of the processing. A Process Controller class will maintain the status of the processes as well as start/ put a process in queue.

  1. Call the the Start Processing servlet starts a process and returns a unique ID representing the process

  2. JS/JQuery can be used to make periodic requests using the above UID to the Get Processing Progress servlet to know the progress.



来源:https://stackoverflow.com/questions/15788989/status-of-the-process-triggered-by-request-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!