Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何显示blob字段中的图像_Java_Jsp - Fatal编程技术网

Java 如何显示blob字段中的图像

Java 如何显示blob字段中的图像,java,jsp,Java,Jsp,下面我将了解如何显示blob字段中的图像 Blob image = null; byte[ ] imgData = null ; // here i get the blob and i'm sure that 'image' is not null ////////// image = rsListaNews.getBlob("immagine_principale"); imgData = image.getBytes(1,(int)image.length()); respo

下面我将了解如何显示blob字段中的图像

Blob image = null;
byte[ ] imgData = null ;

// here i get the blob and i'm sure that 'image' is not null //////////
image = rsListaNews.getBlob("immagine_principale");    

imgData = image.getBytes(1,(int)image.length());

response.setContentType("image/jpg");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
我得到这个错误

org.apache.jasper.JasperException: org.apache.jasper.JasperException: An exception occurred processing JSP page /Include/Chiusura.jsp at line 70

67:     
68:         response.setContentType("image/jpg");
69: 
70:     OutputStream o = response.getOutputStream();
71: 
72:     o.write(imgData);
73: 

您不应该使用JSP来写入响应OutputStream

您只能在单个请求/响应流中写入响应的编写器或输出流,但不能同时写入两者。很可能在JSP中的某个地方,它已经被写入了编写器(即使只是空白)

二进制数据(如图像)更好地从


此外,您不应该关闭()响应编写器/输出流,因为这是容器的责任

接收字节数组中的图像