mysql 不能存储本地,从Mysql数据库显示图像而不存储到本地系统

I'm developing a Struts application where I want to display images present in MySQL DB in BLOB datatype.

I don't want to store those images to local system but I want to directly display them in a browser. We need to store them in an temp memory.

I am able to fetch it and store it into FileOutputStrem and from this object i need to pass an image to JSP.

Below is the code

ResultSet result = statement.executeQuery();

if (result.next()) {

Blob blob = result.getBlob("photo");

InputStream inputStream = blob.getBinaryStream();

// read the input stream...

}

Please let me know how can I do this.

解决方案

You can use

byte[] content = result.getBytes("photo");

response.setContentType("image/jpg");

response.setContentLength(content.length);

response.getOutputStream().write(content);

Html Code

$(document).ready(function () {

$("#submit").click(function () {

$.ajax({

type: "GET",

url: "servleturl",

success: function (result) {

$("#content").html(''+result+'');

}

});

});

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值