JSP Programming - response.getWriter().flush(); doesn't work

社会主义新天地 提交于 2019-12-04 12:58:59
<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>

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.

You have to set your "Transfer-Encoding: chunked" header before you write your content.

response.setHeader("Transfer-Encoding", "chunked");
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!