[输出流]将图片以流的方式读取并显示

数据库中保存的是clob类型的流

读取方法如下:

<span style="white-space:pre">	</span>private void cxXP(HttpServletRequest request,HttpServletResponse response){
		String userName = (String) request.getSession().getAttribute("username")==null?"":(String) request.getSession().getAttribute("username");
		DBConnection db = null;
		Connection dbCon = null;

		Statement hdLSStmt = null; // 获得历史查询
		ResultSet hdLSRs = null;
		Reader reader = null;
		try {
			String HCHM = request.getParameter("ZJHM") == null ? "" : request.getParameter("ZJHM");
			//String HCHM = request.getParameter("ZJHM") == null ? "" : request.getParameter("ZJHM").replace("\\", "/");
			//HCHM = HCHM.toUpperCase();
			db = new DBConnection("DataSource1");
			dbCon = db.getConnection();
			String sql = "select RWID,xp,length(xp) from QB_RW where RWID='" + HCHM+ "' and length(xp)>0 and rownum=1 ";
			hdLSStmt = dbCon.createStatement();
			hdLSRs = hdLSStmt.executeQuery(sql);
			String xp = "";
			byte[] xp_byte = null;
			if (hdLSRs.next()) { // 说明以前查过该号码.并且是真号码
				Clob clob_xp = hdLSRs.getClob("XP");
				if (clob_xp != null) {
					reader = clob_xp.getCharacterStream();
					int l = (int) clob_xp.length();
					char[] c = new char[l];
					int length = 0;
					while ((length = reader.read(c, 0, l)) != -1) {
						xp += new String(c, 0, length);
					}
				}
				if (reader != null) {
					reader.close();
				}
				BASE64Decoder decode = new BASE64Decoder();
				xp_byte = decode.decodeBuffer(xp);
			}
			if ("".equals(xp) && xp_byte == null) {
				try {
					String serverPath = request.getSession().getServletContext().getRealPath("/");
					File f = new File(serverPath, "/img/wtp.jpg");
					if (f.exists()) {
						InputStream in = new FileInputStream(f);
						xp_byte = new byte[in.available()];
						in.read(xp_byte);
						in.close();
					} else {
						xp_byte = new byte[0];
					}
				} catch (IOException e) {
					xp_byte = new byte[0];
				}
			}
			response.setContentType("image/gif");
			response.getOutputStream().write(xp_byte);
			response.getOutputStream().flush();
			response.getOutputStream().close();
		} catch (IOException e) {
	
		} catch (Exception e) {
			Tools.errorList(e, userName);
		} finally {
			try {
				if (hdLSRs != null) {hdLSRs.close();}
				if (hdLSStmt != null) {hdLSStmt.close();}
				if (dbCon != null) {dbCon.close();}
				if (db != null) {db.close();}
			} catch (Exception e) {
			}
		}
	}
前台在extjs的grid列中显示:
<pre name="code" class="javascript"><span style="white-space:pre">	</span>{
		header : "照片",
		width : 110,
		sortable : true,
		dataIndex : 'RWID',
		renderer : function(hm) {
			return '<img src='+basePath+'servlet/front/LHXDS?type=cxXP&ZJHM='+hm+'&t='+new Date().getTime()+' width=100 height=100>';
		}
	}


 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值