Reputation: 787
<%
response.getWriter().write("Hello world<BR>\n");
response.getWriter().flush();
wait(10000); // 10 seconds
response.getWriter().write("Goodbye happiness.<BR>\n");
%>
Expected results: "Hello World" is displayed in the browser. 10 seconds later, "Goodbye happiness." is displayed.
What happens: The page sits there loading for 10 seconds, and then "Hello World Goodbye Happiness" are displayed at the end.
What I want to do is display the status of a long-running operation as different milestones are reached. Is this possible?
I'm using Eclipse EE (with Tomcat) on Windows 7.
Upvotes: 3
Views: 13268
Reputation: 15446
I think the problem here is wait(10000); // 10 seconds
. Not sure what response you are seeing but you have to take lock before doing wait()
. You should change wait(10000);
line to one of this :
synchronized (this){
wait(10000); //10 secs
}
OR
Thread.sleep(10000);
Even then if it does not work you should be checking if there is anything behind which is overriding writer and buffering the data until close.
Upvotes: 1
Reputation: 4474
<html>
<body>
You didn't tell us which browser you were using. Chrome and Firefox behave as you expect them to do.
But, IE needs some filler at the start of the page. IE will wait for a certain amount of content to render.
I am testing with IE8 and this works for me.
<br/>
<%
out.print("Hello world<br/>");
out.flush();
Thread.sleep(3000); // 3 seconds for easy testing.
out.print("Goodbye happiness.");
%>
</body>
</html>
Upvotes: 3
Reputation: 21
You have to set your "Transfer-Encoding: chunked" header before you write your content.
response.setHeader("Transfer-Encoding", "chunked");
Upvotes: 0