How can I send text output to a browser page to show the progress of an operation, which can take about 15-20 seconds? I tried to directly write the HttpServletResponse
output stream, but the user still sees the full output after the completion of the whole process.
This is what I have tried so far
@RequestMapping(value = "/test") public void test(HttpServletResponse response) throws IOException, InterruptedException { response.getOutputStream().println("Hello"); response.getOutputStream().flush(); Thread.sleep(2000); response.getOutputStream().println("How"); response.getOutputStream().flush(); Thread.sleep(2000); response.getOutputStream().println("are"); response.getOutputStream().flush(); Thread.sleep(2000); response.getOutputStream().println("you"); response.getOutputStream().flush(); }
source share