Re: [JSP ] 從資料庫抓圖
是要寫在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)
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 5 之 12 篇):