當我運行此代碼,illegalException ::響應的getWriter()已被定義
illegalException ::響應的getWriter()已定義。
<%
Blob image = null;
Connection con = null;
byte[ ] imgData = null ;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hicheck","root","root");
stmt = con.createStatement();
String s="sivabrahma";
PreparedStatement ps=con.prepareStatement("select photo from hic_relation where email=? ");
ps.setString(1,"sivabrahma");
rs=ps.executeQuery();
if (rs.next()) {
image = rs.getBlob(1);
imgData = image.getBytes(1,(int)image.length());
}
else {
out.println("Display Blob Example");
out.println("image not found for given id");
return;
}
// display the image
response.setContentType("image/gif");
response.getOutputStream();
ServletOutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
System.out.println(o.toString());
System.out.println(imgData.toString());
} catch (Exception e) {
out.println("Unable To Display image");
out.println("Image Display Error=" + e.getMessage());
// return;
} finally {
try {
rs.close();
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
} %>
當我從檢索數據庫異常圖像發生。
你的問題是不準確的。 1)例外的名稱不正確。 2)從數據庫中檢索圖像時不會發生異常:它發生在那之後。此外,有關Java異常的幫助問題應始終包含完整的堆棧跟蹤。 –