title: Retriving image from mysql database and display it in html page
body: <p>I am simply trying to retrieve a image from database and display it. I have written the following code:</p>
  
  <pre><code>    RetreiveImage.java
  
      import myconnection.ConnetionDefault;
      import java.sql.*;
      import java.io.*;
      import javax.servlet.*;
      import javax.servlet.http.*;
      public class RetreiveImage extends HttpServlet{
      public void doGet(HttpServletRequest request, HttpServletResponse response)         throws         ServletException, IOException{
      PrintWriter out = response.getWriter();
      Connection con=null;
      String id=request.getParameter("id");
      try{
      con=ConnetionDefault.getConnection();
      ResultSet results = null;
      PreparedStatement ps = null;
      ps = con.prepareStatement("select picture from pic_229084519 where pic_id=?");
      ps.setString(1,id);
      results = ps.executeQuery();
      String imgLen="";
      if(results.next()){
      imgLen = results.getString(1);
      System.out.println(imgLen.length());
  
  
      int len = imgLen.length();
      byte [] rb = new byte[len];
      InputStream readImg = results.getBinaryStream(1);
      int index=readImg.read(rb, 0, len);
      System.out.println("index"+index);
      ConnetionDefault.close(results,ps,con);
      response.reset();
      response.setContentType("image/jpg");
      response.getOutputStream().write(rb,0,len);
      response.getOutputStream().flush();
  
      RequestDispatcher rd=request.getRequestDispatcher("gg.html");
      rd.forward(request,response);
      }
      } catch (Exception e){
  
      e.printStackTrace();
      }
      }
      }
  
      retImagel.html
  
      &lt;html&gt;
      &lt;head&gt;
      &lt;title&gt;Login&lt;/title&gt;
  
      &lt;/head&gt;  
      &lt;body bgcolor="Gold"&gt;
      &lt;center&gt;
  
      &lt;form action="ret.pic"&gt;
      &lt;table&gt;
      &lt;tr&gt;&lt;th&gt;Namme&lt;/th&gt;&lt;td&gt;&lt;input type="text" name="id" size="3"/&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
  
      &lt;td&gt;&lt;input type="submit" value="Get"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="reset"     value="Cancel"/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;/table&gt;
      &lt;/form&gt;
  
      &lt;/center&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  
      gg.html
  
      &lt;html&gt;
      &lt;head&gt;
       &lt;title&gt;Login&lt;/title&gt;
  
      &lt;/head&gt;  
      &lt;body bgcolor="Gold"&gt;
  
      &lt;img src="/ret.pic?id=${id}"/&gt;
      &lt;/center&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>My problem is its displaying image in default response page. but i want it in gg.html where i am going wrong.. pls help me.</p>