有好久一段時間沒有來寫東西拉,最近的情緒不太好,老是在思考將來,同時也不滿現狀.
今天終于有一點想通了 ,路是自己選的,還是盡量將現在的路走好.將來的事留給明天吧.
送一段比較現實的格言,只要有錢,年齡不是問題,身高不是距離.
操作CSV文件有用的兩個類:CSVprinter,CsvDriver.
?
getOutputStream() has already been called for this response問題的解決?????
在jsp向頁面輸出圖片的時候,使用response.getOutputStream()會有這樣的提示:java.lang.IllegalStateException:getOutputStream() has already been called for this response,會拋出Exception
原因一:
?JSP默認的輸出流為PrintWriter ,即<% %>以外的東西所默認的輸出方式,如果你嘗試在JSP中使用ServletOutputStream就會引起錯誤.要嘛直接改用Servlet輸出(復寫service方法),要嘛刪除除%><%中的任何東西(包括HTML標簽,空格,回車等東西)應該就可以。
對于這樣的情況應該這樣來解決,刪除%><%之間的所有內容包括空格和換行符,最后也要消除空格和換行符,最好再加上一句response.reset()。
原因二:
?????
在J2EE的API參考里有這么個:
ServletResponse的getWriter()方法里會拋出這個異常,
IllegalStateException - if the getOutputStream method has already been called
for this response object
而它的getOutputStream()方法里會拋出這個異常.
IllegalStateException - if the getOutputStream method has already been called for this response object
并且兩者的函數申明里都有這么樣的一句
Either this method or getOutputStream() may be called to write the body, not both.
Either this method or getWriter() may be called to write the body, not both.
?以上說明也解釋了為什么在往頁面中寫入圖片的時候要使用如下循環格式
OutputStream output=response.getOutputStream();
?while((len=in.read(b)) >0)
??{
??output.write(b,0,len); ?
??
??}
?output.flush();
而不是把response.getOutputStream().write()放到循環體內