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){
There is also a great example of a long javascript poll on StackOverflow.
source share