java 怎么把byte[]转换成图片显示在页面上
1个回答
展开全部
Servlet的doGet/doPost中
httpResponse.setHeader("Content-Type", "image/jpeg");
String sql = "SELECT * FROM User WHERE ID = 2";
statement = connection.createStatement();
resultSet = statement.executeQuery(sql);
InputStream in = null;
OutputStream out = httpResponse.getOutputStream();
while (resultSet.next()) {
// 读取BLOB
Blob blob = resultSet.getBlob("image");
in = blob.getBinaryStream();
byte[] blobBuffer = new byte[1024];
int length = 0;
while ((length = in.read(blobBuffer)) != -1) {
out.write(blobBuffer, 0, length);
}
}
in.close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询