[摘要:本日正在開辟過程當中發明一個題目:正在頁里中應用了jsp:forward扔錯Attempt to clear a buffer that's already been flushed!! 百思沒有得其解!! 谷歌之,得以下說明: 通例,先上中文論壇搜刮謎底 h]
今天在開發過程中發現一個問題:在頁面中使用了<jsp:forward>拋錯Attempt to clear a buffer that's already been flushed!!
百思不得其解!!
google之,得如下解釋:
慣例,先上外文論壇搜索答案
http://www.coderanch.com/t/484489/JSP/java/JSP-working
其中有一句話,解釋了這個問題的發生:
When you forward a request to another resource.. whose response is already commited.. then it throws this exception.
A request that is being forwarded should not have commited.
In your case, when the JSP is being executed, it might have generated some html content before it is forwarding.
If the server has send these html content to a client before you forward the request to another resource, then it throws an illegal state exception if you try to forward.
As you increased the buffer size, then the server is not actually sending the generated html content to client (Till the buffer fills up).. and on forward the buffer will be cleared.
意思大致是:當你通過forward請求另一個資源的時候,如果你的服務器已經向client響應了數據,就是所你原來未跳轉之前的頁面已經存在數據了(我的頁面情況是:forward前面通過連接數據庫查詢到數據賦值給了select下拉列表了),所以就會報錯,而設大緩沖區的話,服務器就不會立即響應給服務端,而是等所有頁面加載完成之后,或者緩沖區滿了之后才會發送響應給用戶,
我的解決辦法,在jsp開頭加入緩沖區設置語句
1 <%@ page autoFlush="true" buffer="1094kb"%>
buffer大小視實際情況來定。。
原文出處(http://www.ithao123.cn/content-100640.html)