[JSP ] 有關out.close()

看板java作者 (Q毛)時間15年前 (2011/02/23 16:55), 編輯推噓0(0011)
留言11則, 2人參與, 最新討論串1/1
是這樣的 小弟寫了一個jsp網頁 程式內容大概如下 while((line = correctExecuteInfo.readLine()) != null{ out.println(line+"<br/>"); out.flush(); } </body> </html> <% out.close(); shutdownService();%> /// 這裡會執行約30sec 當程式跑到out.close()時 會出現stream error excption 但我確定後面並沒有任何資料要輸出了 (因為shutdownService()是屬於model的部分) 程式原意是這樣 我希望能將執行結果印出 印完後我必須關掉特定service,但網頁中因執行了shutdownService() 所以 網頁一直處於loading狀態. 但我希望網頁不須處於loading 但 程式能執行到最後一行的shutdownService() 想請問各位前輩跟高手們 這應該怎麼做比較好. 是否是out.close()有什麼需要注意的嗎? pm 4:57 對了 我先前先使用servlet寫的時候 並不會遇到excpetion 其原因是? pm 5:32 我已經找到您說的 ***_jsp.java了 out.write("\n"); out.write("</body>\n"); out.write("</html>\t\t\t\t\t\t\t\t\n"); out.write("\t "); out.flush(); // 這行有放跟沒放都會出現Stream closed out.close(); executeService.ShutDowm_Service(task); } catch (Throwable t) {//省略... } finally { //省略 } 但 似乎後面的確沒有關於jsp的output了 pm 5:39 還是需要的是改換我的程式想法呢??- -q pm 6:35 嘗試將shutdownService() 註解 並在最尾端(包括/<body> 與 </html>) 之後再將 out.flush(); out.close(); 還是會出現stream closed @@ pm 7:12 確認buffer 已經清乾淨為8192後 才執行out.close(); 還是出現stream closed @@ pm 8:17 其原因找到了.. close public abstract void close() throws IOException Close the stream, flushing it first. This method needs not be invoked explicitly for the initial JspWriter as the code generated by the JSP container will automatically include a call to close() 但要怎麼不讓容器幫我close這個out,該改寫哪一段code @@ -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.126.162.22 ※ 編輯: simon8233 來自: 59.126.162.22 (02/23 16:57)

02/23 17:05, , 1F
只要執行一次out.flush就可以
02/23 17:05, 1F

02/23 17:15, , 2F
順便去檢查一下,jsp檔轉譯出來的xxx_jsp.java
02/23 17:15, 2F

02/23 17:19, , 3F
請問在eclipse中那個檔案要去哪裡找@@
02/23 17:19, 3F

02/23 17:27, , 4F
突然想到用find就好 非常謝謝你的意見 我看一下此文件@@
02/23 17:27, 4F
※ 編輯: simon8233 來自: 59.126.162.22 (02/23 17:37) ※ 編輯: simon8233 來自: 59.126.162.22 (02/23 17:40) ※ 編輯: simon8233 來自: 59.126.162.22 (02/23 18:39) ※ 編輯: simon8233 來自: 59.126.162.22 (02/23 19:14) ※ 編輯: simon8233 來自: 59.126.162.22 (02/23 20:19)

02/23 23:22, , 5F
我用tomcat 6.0.30 測試ok ...
02/23 23:22, 5F

02/24 00:34, , 6F
? 真假! 我用的版本是tomcat 6.029@@
02/24 00:34, 6F

02/24 01:02, , 7F
測試換了6.0.32 還是不行
02/24 01:02, 7F

02/24 10:33, , 8F
你把發生問題時,所使用的xxx_jsp.java貼上來
02/24 10:33, 8F

02/24 17:26, , 9F
好 稍等
02/24 17:26, 9F

02/24 17:36, , 10F
已經附上轉出的result.jsp 非常感謝你一直幫我找解決的方法@@ 我也還在想看看是不是能從model那邊下手更改的問題 ※ 編輯: simon8233 來自: 59.126.162.22 (02/24 17:36) ※ 編輯: simon8233 來自: 59.126.162.22 (02/24 17:37)

02/24 19:14, , 11F
jsp裡面不能用out.close(),所以你要重新設計一下你的流程了
02/24 19:14, 11F
文章代碼(AID): #1DPCkGtI (java)