我正在尝试将 HTTP 流与 servlet 一起使用。在本地,我使用 orion 作为 servlet 容器,它工作正常,但在运行 JRUN 4.0 的测试服务器上,即使我在输出流上调用 flush(),输出也会被缓冲。关于为什么输出被缓冲以及我能做些什么来阻止它的任何想法?
OutputStream os = servletResponse.getOutputStream();
while (true)
{
//attempt to write to output before doing anything else. If browser has disconnected, an IOException will be thrown so nothing else will be done
os.write(".".getBytes());
os.flush();
String response = getData();
os.write(response.getBytes());
os.flush();
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
}
}