2014-02-16 41 views
0

我尝试从Oracle数据库访问图像数据并在jsp上显示图像。写下面的代码。 在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(); 
} 
%> 

当运行此代码并使用IE浏览器,然后显示图像有错误

[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

希望能帮助

我建议使用字符串,如果它虽然显示我们需要将字符串追加到位置存储在Oracle数据库 图像名

<% 
try 
{ 
    ResultSet rs=stmt.executeQuery("select * from PICTABLE where ID=200"); 
    if(rs.next()) 
    { 
     String b1=rs.getString("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(); 
} 
%> 
<img src="foldername/<%=b1%>" style="height:200px;"/>