Re: [JSP ] 從資料庫抓圖

看板java作者 ( )時間18年前 (2007/12/25 10:45), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/12 (看更多)
是要寫在jsp裡...我也不知道能不能全秀 先試試看秀出一個 做了一些修正 <% String conAAA = APCMDUtility.nts(request.getParameter("AAA")); String fileName1 = APCMDUtility.nts(request.getParameter("fileName1")); response.setContentType("IMAGE/JPG"); response.setHeader("Content-Disposition", "attachment; filename="+fileName1); String sqlcmd =""; pstmt = null; con = null; rs=null; ck = null; DB = new DBenergy(); ServletOutputStream stream = response.getOutputStream(); con = DB.getConnection(); sqlcmd = "select * from table " + "where AAA=? order by BBB"; pstmt = con.prepareStatement(sqlcmd); pstmt.setString(1,conAAA); rs=pstmt.executeQuery(); InputStream attachedFile1 =null; if(rs.next()){ attachedFile1= rs.getBinaryStream(1); } BufferedInputStream in = new BufferedInputStream (attachedFile1); try{ byte[] buf = new byte[3*1024*1024]; int length; while((length = in.read())!=-1){ stream.write(buf,0,length); } }finally{ in.close(); stream.close(); if(attachedFile1!=null){ attachedFile1.close(); } } %> 但是會有Exception Finally:Exception:java.lang.IllegalStateException: getWriter() has already been called for this response 看不懂= =" -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.173.49.133 ※ 編輯: cloud1203 來自: 202.173.49.133 (12/25 12:34)
文章代碼(AID): #17S6xJIU (java)
討論串 (同標題文章)
文章代碼(AID): #17S6xJIU (java)