2 在数据库有blob格式可以存放图片 以二进制流的方式取出来
<% String zjbm = CheckParam(request.getParameter("zjbm"),"") String zpSql = "select zp from tjjryxxx where sfzh = '"+zjbm+"'" out.clear() response.setContentType("image/jpeg") response.setHeader("Content-Transfer-Encoding","base64") Connection connection = null PreparedStatement ps = null ResultSet rs = null Blob blob =null byte[] data = null try{ connection =getConn() ps = connection.prepareStatement(zpSql) rs = ps.executeQuery() while(rs.next()){blob = (Blob)rs.getBlob("zp") long nlen = blob.length() int nsize = (int) nlen data = blob.getBytes(1,nsize) OutputStream out1 = response.getOutputStream() BufferedOutputStream bos =null bos = new BufferedOutputStream(out1) bos.write(data,0,data.length) bos.close() rs.close() } }catch(Exception e){ e.printStackTrace()} %>
这是用Struts做的<img src="<bean:write name="item" property="page"/>" width="100" height="100">
图片文件夹必须在服务器里
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)