title: Retrieve image from database in JSP (but I'm not able to retrieve image in particular location)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2340406/how-to-retrieve-and-display-images-from-a-database-in-a-jsp-page">How to retrieve and display images from a database in a JSP page?</a>  </p>
  </blockquote>
  
  
  
  <p>I want to display an image in a <code>&lt;td&gt;</code> tag of a table. The code is working fine but I am not able to retrieve the image in the <code>&lt;td&gt;</code> tag of the table</p>
  
  <pre><code>&lt;%@page contentType="text/html"%&gt;
  &lt;%@page pageEncoding="UTF-8"%&gt;
  &lt;%@page import="java.sql.*,java.io.*"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
          &lt;title&gt;Untitled Document&lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection con = DriverManager.getConnection("jdbc:odbc:IMG");
          Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
          ResultSet rs=st.executeQuery("select image from img");
  
          %&gt;
          &lt;table width="100%" border="2"&gt;
              &lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;%
              while(rs.next()) {
              byte[] bytearray = new byte[1048576];
              int size=0;
              InputStream sImage = rs.getBinaryStream(1);
  
              response.reset();
              response.setContentType("image/jpeg");
              while((size=sImage.read(bytearray))!= -1 ){
              %&gt;
              &lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&lt;img src="&lt;%= response.getOutputStream().write(bytearray,0,size)%&gt;"width=50 height=50 /&gt;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;%
              }
              }     
              %&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>