How can I write a download page with a playback frame

I would like to implement a page that will be displayed to the user during the execution of the system command. Once the command completes, the user should be redirected to another page.

What are some strategies for implementing this?

(A solution without javascript would be ideal)

+6
source share
1 answer

This can definitely be done. You want to see asynchronous programming with HTTP in the documentation that explains how to do this in a non-blocking way. However, you will need some javascript for the redirecting part.

And I don’t know what you mean by "system command", but you probably want to create a job for it , so you can call it with a request. You can interrogate it before its completion, and then redirect the user. But actually the documentation does an infinitely better job, explaining it, and then I do now.

Here is an example of a controller action in which I assume that your system command returns some kind of line output for the user. When the task is completed, it will send a response to the user, thereby initiating a success handler in the javascript example.

public static void executeSystemCommand(String input) { Promise<String> outputPromise = new SystemCommandJob(input).now(); String output = await(outputPromise); renderText(output); } 

Basically, if you use jQuery $.ajax , you can use the full event to query the data (just repeat the request if it failed during the timeout) and use the success / done event to redirect the user when the application responds to indicate that "system command" completed.

An example of a function that you could use:

 function poll(){ $.ajax({ url: "/systemcommand", success: function(data){ // redirect to next page here document.location.href = '/output' }, complete: poll, timeout: 20000 }); }; 

There is also a great example of a long javascript poll on StackOverflow.

+4
source

Source: https://habr.com/ru/post/910705/


All Articles