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" />数据库中读取blob,jsp显示图片