关于PrintWriter里面的flush方法

Http有个响应头,trunk平时下载的时候,服务器会自动处理,但如果我们想自己手动分段返回是否可行呢?

写了一个代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
protected void service(final HttpServletRequest request,final HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/plain");
response.getWriter().write("response1");
try {
Thread.sleep(3000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
response.getWriter().write("response2");
try {
Thread.sleep(3000L);
} catch (InterruptedException e) {
}
response.getWriter().write("response3");
}
阅读更多