我正在开发一个 Struts 应用程序,我想在其中以 BLOB 数据类型显示 MySQL DB 中存在的图像。
我不想将这些图像存储到本地系统,但我想直接在浏览器中显示它们。我们需要将它们存储在临时内存中。
我能够获取它并将其存储到 FileOutputStrem
中,并且我需要从该对象将图像传递到 JSP。
下面是代码
ResultSet result = statement.executeQuery();
if (result.next()) {
Blob blob = result.getBlob("photo");
InputStream inputStream = blob.getBinaryStream();
// read the input stream...
}
请让我知道我该怎么做。
最佳答案
你可以使用
byte[] content = result.getBytes("photo");
response.setContentType("image/jpg");
response.setContentLength(content.length);
response.getOutputStream().write(content);
HTML代码
$(document).ready(function () {
$("#submit").click(function () {
$.ajax({
type: "GET",
url: "servleturl",
success: function (result) {
$("#content").html('<img src="'+result+'" >');
}
});
});
});
关于java - 显示来自Mysql数据库的图像,而不存储到本地系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29249549/