我尝试从oracle数据库访问图像数据并在jsp上显示图像。写下面的代码。
<%
try
{
ResultSet rs=stmt.executeQuery("select * from PICTABLE where ID=200");
if(rs.next())
{
Blob b1=rs.getBlob("PIC");
byte x[]=b1.getBytes(1, (int)b1.length());
OutputStream o=response.getOutputStream();
o.write(x);
o.close();
}
System.out.println("Done");
}
catch(Exception ex)
{
ex.printStackTrace();
}
%>
<%
try
{
ResultSet rs=stmt.executeQuery("select * from PICTABLE where ID=200");
if(rs.next())
{
Blob b1=rs.getBlob("PIC");
byte x[]=b1.getBytes(1, (int)b1.length());
OutputStream o=response.getOutputStream();
o.write(x);
o.close();
}
System.out.println("Done");
}
catch(Exception ex)
{
ex.printStackTrace();
}
%>
运行此代码并使用IE浏览器时,显示图像出错
当使用chrome浏览器时,图像数据不会以图像格式转换,并且会出现上面的大厦错误。如何为每个浏览器解决此问题。[java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response
答案 0 :(得分:0)
你之前在这个页面上调过了getWriter()somwhere吗? 来自文档:
可以调用此方法或getWriter()来编写正文,而不是两者。
http://docs.oracle.com/javaee/5/api/javax/servlet/ServletResponse.html#getOutputStream()