title: image is not loaded from database in jsp page
body: <p>i am trying to display table data from database to jsp page, all  data are fetched but image is not loaded into image tab. i have store image as a BLOB in table.</p>
  
  <p>my jsp page is follow :</p>
  
  <pre><code>&lt;body&gt;
      &lt;table border="1"&gt;  
  
      &lt;%@ page import="com.*;"%&gt;
      &lt;%
          MySql myobj = new MySql();
          myobj.connect();
  
          String query="select contact_id,first_name,last_name,photo from contacts";
  
          ResultSet rs = myobj.getdata(query);
  
          while(rs.next())
          {               
  
          %&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;%= rs.getInt(1) %&gt;             
                  &lt;/td&gt;
  
                  &lt;td&gt;
                      &lt;%= rs.getString(2).toString() %&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;%= rs.getString(3).toString() %&gt;
                  &lt;/td&gt;
  
                  &lt;td&gt;
                      &lt;img src="&lt;%= rs.getString(4) %&gt;"  width="500" height="300" alt="data"&gt;&lt;/img&gt;                   
                  &lt;/td&gt;
  
              &lt;/tr&gt;
          &lt;% 
  
          }
      %&gt;
  
  
      &lt;/table&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>i have to also implement download when item name or data of second div is clicked then that related data should be downloaded. </p>
  
  <blockquote>
    <p>can anyone solve my this problem soon ?</p>
    
    <p>how to implement download in servlets as back end ?</p>
  </blockquote>
  
  <p>i have write this code for imageservlet :</p>
  
  <pre><code>protected void doGet( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
      {   
          String id = request.getParameter("contact_id");     
          MySql myobj = new MySql();
          myobj.connect();
          PrintWriter out=response.getWriter();       
          try
          {
              String query="select photo from contacts where contact_id='"+id+"'";
  
              ResultSet rs = myobj.getdata(query);
  
              out.println(id);
  
              Blob image=null;
              byte[] imgData = null;
              image= rs.getBlob(1);
              imgData = image.getBytes(1, (int) image.length());
              response.setContentType("image/gif");
              OutputStream o = response.getOutputStream();
              o.write(imgData);
              o.flush();
              o.close(); 
              response.sendRedirect("Message.jsp");
          }
          catch (Exception e)
          {
              e.getMessage();
          }       
      }
  </code></pre>