嗨我想在JSP中显示图像,并能够在div,classs中处理它,希望如图像ej:<img src="image from MySQ">
。如何在JSP中显示来自MySQL(BLOB)的图像?
我有以下代码,但它显示全屏幕图像。
<%Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, login, password);
statement = conn.createStatement();
rs = statement.executeQuery("SELECT photo FROM contacts where contact_id='1'");
try {
if (rs.next()) {
response.setContentType("image");
InputStream is = rs.getBinaryStream(1);
OutputStream aux = response.getOutputStream();
out.println("jajaja");
byte[] buffer = new byte[4096];
for (;;) {
nBytes = is.read(buffer);
if (nBytes == -1) {
break;
}
aux.write(buffer, 0, nBytes);
}
is.close();
aux.flush();
aux.close();
} else {
throw new SQLException("image not found");
}
rs.close();
} catch (SQLException e) {
out.println("Imagen no encontrada");
}
out.println("no se muestra");%>