//設置輸出類容的類型,按照下面設置后flush()才會起作用
response.setContentType("text/html; charset=UTF-8");
request.setCharacterEncoding("UTF-8");
PrintWriter writer = response.getWriter();
for(int index = 0 ;index < 5 ;index++){
writer.write("你好!<br />");
writer.flush();
try {
Thread.sleep(1000);
} catch (InterruptedException e) { }
}
writer.close();
/***
不設置ContentType直接使用flush()不會有作用。
如果要flush()起作用,必須先向緩沖區填充一定的內容(測試為1024個字符)。
網上看到的原因是容器認為緩沖區的內容過少發送的效率不高。
設置了ContentType為text/html后,flush()就會立即起作用。
可能是因為動態生成Html的時候加載數據比較耗時,可以先返回后讓瀏覽器解析樣式。(個人猜想)
上面的內容沒有在任何的官方文檔中看到。唯一在官方文檔中看到和內容大小有關系的是關于Buffer大小的設置:
***/
/***
不設置ContentType直接使用flush()不會有作用。
如果要flush()起作用,必須先向緩沖區填充一定的內容(測試為1024個字符)。
網上看到的原因是容器認為緩沖區的內容過少發送的效率不高。
設置了ContentType為text/html后,flush()就會立即起作用。
可能是因為動態生成Html的時候加載數據比較耗時,可以先返回后讓瀏覽器解析樣式。(個人猜想)
上面的內容沒有在任何的官方文檔中看到。唯一在官方文檔中看到和內容大小有關系的是關于Buffer大小的設置:
setBufferSize
public void setBufferSize(int size)
- Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as large as the size requested. The actual buffer size used can be found using
getBufferSize
.A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.
This method must be called before any response body content is written; if content has been written or the response object has been committed, this method throws an
IllegalStateException
. - Parameters:
size
- the preferred buffer size- Throws:
java.lang.IllegalStateException
- if this method is called after content has been written- See Also:
getBufferSize()
,flushBuffer()
,isCommitted()
,reset()
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletResponse.html#setBufferSize(int)
***/
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
25 | 26 | 27 | 28 | 29 | 30 | 31 | |||
1 | 2 | 3 | 4 | 5 | 6 | 7 | |||
8 | 9 | 10 | 11 | 12 | 13 | 14 | |||
15 | 16 | 17 | 18 | 19 | 20 | 21 | |||
22 | 23 | 24 | 25 | 26 | 27 | 28 | |||
29 | 30 | 1 | 2 | 3 | 4 | 5 |
常用鏈接
留言簿
隨筆分類
隨筆檔案
文章檔案
搜索
最新評論

- 1.?re: javascript將base64編碼的圖片數據轉換為file并提交
- 感謝
- --njbble
- 2.?re: javascript將base64編碼的圖片數據轉換為file并提交
- 太棒了,試了好多方法,終于看到這個了!感謝
- --Rhine
- 3.?re: javascript將base64編碼的圖片數據轉換為file并提交[未登錄]
- 轉blob 不兼容怎么做?
- --aa