<body>
<%
//获取图片对象(根据主键)的sql语句
String showImage = " select * "+
" from 存放图片的表 "+
" where id=‘1‘ " ;
BufferedInputStream inputImage = null;
try{
//conn为一个Connection对象
Statement st = conn.createStatement();
//获取结果集
ResultSet rs=st.executeQuery(showImage);
//输出文件名
String filename="";
if(rs.next()) {
Blob blob = (Blob)rs.getBlob("BINARYFILE");
filename=rs.getString("FILENAME");
//读取图片字节到数据流中
inputImage = new BufferedInputStream(blob.getBinaryStream());
}
BufferedImage image = null;
image=ImageIO.read(inputImage);
//获取响应的输出流
ServletOutputStream so = response.getOutputStream();
//创建图片到页面
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(so);
encoder.encode(image);
inputImage.close();
}
%>
</body>
<%
catch(Exception e){
}
finally{
closeConn(conn);
}
%>
Blob 存儲文件,读取到页面显示,布布扣,bubuko.com