ext动态显示二进制图片

项目中有个需求,需要在系统动态展示图片,图片是通过流的形式从数据库读取的,网上查的资料要么说通过ext 组件的html属性,html:<img src='../../xx.jpg'/>,要么说通过流在项目文件夹生成图片,然后再用上面的方法来显示,都不能满足要求。于是我就试着将上面的src换成一个到action的请求,竟然很好的实现了需求。

ext js页面,在一个tabpanel里放置一个元素,该元素的html属性如上面所说设置

mainTabPanel.add({
			title : '测试',
			id : 'test',
			autoScroll:true,
			html : '<img src="/.../commonProcessController/getPicture.do?param=id" style="position:absolute;left:0px;top:0px;">'
		});

在controller里面,配置如下映射:

@RequestMapping(value = "/getPicture.do", method = RequestMethod.GET)
public void getProcessPicture(HttpServletRequest request,HttpServletResponse response,String id) throws Exception {
		InputStream inputStream = processEngine.getRepositoryService().getResourceAsStream(processDefinition.getDeploymentId		(), processDefinition.getKey()+".png");
		byte[] buffer = new byte[inputStream.available()];
		inputStream.read(buffer);
		inputStream.close();
		response.reset();
		OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
		toClient.write(buffer);
		toClient.flush();
		toClient.close();
}
大功告成,效果就不截图了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值