【发布时间】:2011-06-22 10:10:45
【问题描述】:
我已将我的image as mediumblob 存储在数据库中
在我的 Image bean 类中,我将照片属性存储为 byte[] 之类的
private byte[] photo;
// getter and setter method for photo
我从数据库中获取图像用于存储在 Image bean 类中
image.setPhoto(resultset.getBinaryStreams(1));
然后我在 Servlet 中得到图像:
InputStream input = null;
OutputStream output = null;
try {
input = new ByteArrayInputStream(image.getPhoto());
output = // What type of stream should I use here
byte[] buffer = new byte[10240];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
} finally {
output.flush();
input.close();
}
问题:
- 我应该在输出行写什么以使用 response.getOutputStream 或其他方式显示照片?
- 这种方法正确还是有更好的方法?
【问题讨论】:
标签: java jakarta-ee inputstream outputstream