[英]display image from Mysql database without storing to local system
I'm developing a Struts application where I want to display images present in MySQL DB in BLOB datatype. 我正在开发一个Struts应用程序,在这里我想以BLOB数据类型显示MySQL DB中存在的图像。
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. 我能够获取它并将其存储到
FileOutputStrem
并且需要从该对象FileOutputStrem
图像传递给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 HTML代码
$(document).ready(function () {
$("#submit").click(function () {
$.ajax({
type: "GET",
url: "servleturl",
success: function (result) {
$("#content").html('<img src="'+result+'" >');
}
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.