jsp从数据库读出的图片显示成了红叉
f601L_ajax_showPic.jsp:
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.io.*,java.sql.*,javax.sql.*,javax.naming.*"%>
<%@ page import="java.util.*"%>
<%
String id = (String) request.getParameter("id");
String selectSql = "SELECT TERMINAL_PICTURE FROM Y_TERMINAL_INFO WHERE ID ='"+id+"'";
//System.out.println("selectSql="+selectSql+" | "+answerId);
boolean isPmsSys = false;
if("pms".equalsIgnoreCase((String)session.getAttribute("sysId"))){
isPmsSys = true;
}
Connection conn = null;
//PreparedStatement ps = null;
Statement ps = null;
ResultSet rs = null;
Blob picture= null;
InputStream in = null;
OutputStream outStream = null;
try {
conn = getConnection(isPmsSys);
ps = conn.createStatement();
rs = ps.executeQuery(selectSql);
byte[] b = new byte[1024];
if (rs.next()) {
picture = (Blob)rs.getBlob("TERMINAL_PICTURE");
}
long size=picture.length();
byte[] bs=picture.getBytes(1,(int)size);
response.setContentType("image/jpeg;charset=GB2312");
response.setHeader("Content-Transfer-Encoding","base64");
outStream=response.getOutputStream();
BufferedOutputStream bos=null;
bos = new BufferedOutputStream(outStream);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(image, "JPEG", bos);
byte[] buf = bos.toByteArray();
bos.write(bs,0,bs.length);
bos.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
cleanup(rs, ps, conn);
if(outStream != null){
outStream.close();
}
if(in != null){
in.close();
}
}
%>
显示jsp:
<img width="140px" height="140px" src="f601L_ajax_showPic.jsp?id=20131030102005" />
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。