我有以下代码来读取 blob 数据并将结果显示为图像。但我得到了错误java.lang.IllegalStateException: getWriter() has already been called for this response
。
while (rs2.next()) {
Blob image = null;
byte[] imgData = null;
j++;
qPaperOptions = rs2.getString(1);
int qDetailId = rs2.getInt(2);
image = rs2.getBlob(5);
ServletOutputStream sout = response.getOutputStream();
// o.close();
// imgData = image.getBytes(1,(int)image.length());
// Blob cnt_data=rs2.getBlob("cimg.ctn_data");
if (image != null) {
// imgData = image.getBytes(1,(int)image.length());
response.setContentType("image/gif");
InputStream in = image.getBinaryStream();
int length = (int) image.length();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
while ((length = in.read(buffer)) != -1) {
sout.write(buffer, 0, length);
}
}
}
我能做些什么来解决这个错误?