这是在动作类中检索图像的代码。我试过了,但无法显示它我不知道图像处理。我应该如何在 JSP 中使用标签来显示图像?
public String displayImage()
{
Connection con = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String sql,result="";
con=JdbcHelper.getConnection();
if(con!=null)
{
try
{
sql = "SELECT INPUT_FILE_BLOB FROM message_details where message_id=?";
preparedStatement = con.prepareStatement(sql);
preparedStatement.setString(1, messageid);
resultSet = preparedStatement.executeQuery();
if(resultSet.next())
{
Blob image = resultSet.getBlob("INPUT_FILE_BLOB");
System.out.println("=============Image2\n" +image);
int len1 = (int) image.length();
System.out.println("=============len1\n" +len1);
byte [] rb1 = new byte[len1];
InputStream readImg1 = resultSet.getBinaryStream(1);
try {
int index1=readImg1.read(rb1, 0, len1);
System.out.println("index1"+index1);
response.reset();
response.setContentType("image/jpg");
response.getOutputStream().write(rb1,0,len1);
response.getOutputStream().flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
catch(SQLException e)
{
try
{
con.rollback();
}
catch (SQLException e1)
{
result = e1.getMessage();
e.printStackTrace();
}
result = e.getMessage();
e.printStackTrace();
}
finally
{
JdbcHelper.close(resultSet);
JdbcHelper.close(preparedStatement);
JdbcHelper.close(con);
}
}
else
result = Constants.SUCCESS;
}