Servlet输出流不用jrun刷新

时间:2013-12-03 20:35:52

标签: servlets outputstream jrun

我正在尝试将HTTP Streaming与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)
    {

    }
}

0 个答案:

没有答案