Java 如何显示blob字段中的图像
下面我将了解如何显示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 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中的某个地方,它已经被写入了编写器(即使只是空白) 二进制数据(如图像)更好地从
此外,您不应该关闭()响应编写器/输出流,因为这是容器的责任 接收字节数组中的图像