[英]how to get image from mysql database saved as blob by java,and show this image in browser with jsp
我想從mysql
數據庫中檢索圖像,該圖像由java保存為blob,並且還想在瀏覽器中顯示該圖像,我試圖通過getBinaryStream()
獲取圖像並將其輸入InputStream
並且還使用了FileOutPutStream()
但是我不知道如何以及必須傳遞到圖像標簽的src
屬性的哪個參數才能在瀏覽器中顯示圖像
inputStream=rs.getBinaryStream("image");
FileOutputStream fos=new FileOutputStream("abc.jpg");
int x;
while((x=inputStream.read())!=-1){
fos.write(x);}
只需寫入響應OutputStream即可:
InputStream in = rs.getBinaryStream("image");
OutputStream out = response.getOutputStream();
int x;
while ((x = in.read()) != -1) {
out.write(x);
}
out.flush();
out.close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.