问题
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.
Call the the Start Processing servlet starts a process and returns a unique ID representing the process
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