In our requirement we need to display the images on a JSP and these images are stored in database. I can get the image from database uwing rs.getBinaryStream() and I can see the image on the jsp page.
but I get the exceptions on server console
java.lang.IllegalStateException: Cannot forward. Response already committed.
and on jsp I see two kinds of exception
1) Original Exception:
Error Message: Cannot forward. Response already committed.
2) Error Page Exception:
Error Message: SRVE0199E: OutputStream already obtained
Error Code: 0
Servlet code :
ResultSet rs =stmt.executeQuery("select Q1IMG from Q1A1 where Q1A1='qw1'");
String imgLen="";
if(rs.next()){
imgLen = rs.getString(1);
}
rs =stmt.executeQuery("select Q1IMG from Q1A1 where Q1A1='qw1'");
if(rs.next()) {
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
log.debug("index "+index);
rs.close();
response.getOutputStream().write(rb);
response.getOutputStream().flush();
}
what could be the reason? how we can avoid them?
could some one please give me solution.
Thanks
Sumant