title: jsp image display
body: <p>I have tried this code to display image from MySQL database using blob...image is not visible.
  I have used this code.</p>
  
  <p>Please rectify this error</p>
  
  <pre><code>&lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;img src="WEB-INF/New folder/birthhappy birthday.jpeg"
           width="65" height="71" alt="birthhappy birthday"/&gt;    
          &lt;H1&gt;Database Lookup&lt;/H1&gt;
          &lt;FORM ACTION="base.jsp" METHOD="POST"&gt;
              Please enter the ID of the publisher you want to find:
              &lt;BR&gt;
              &lt;input type="text" name="imagename"&gt;
              &lt;BR&gt;
              &lt;INPUT TYPE="SUBMIT" value="Submit"&gt;
          &lt;/FORM&gt;
  
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>base.jsp :</p>
  
  <pre><code>&lt;%@page import="java.io.OutputStream"%&gt;
  &lt;%@ page import="java.sql.*" %&gt;
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
           &lt;% 
  
          Class.forName("com.mysql.jdbc.Driver");
          Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/searchimg","root","");
           Statement stmt = con.createStatement();
            //String id = request.getParameter("id"); 
            String imagename=request.getParameter("imagename");
  
            ResultSet resultset =stmt.executeQuery("select * from friendupload where imagename = '" +imagename.trim()+ "' ") ; 
  
   while(resultset.next())
  {
  
  
  
  
  %&gt;                                      
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt; &lt;%=resultset.getString(1)%&gt;         &lt;/td&gt;
          &lt;td&gt;   &lt;%=resultset.getString(2) %&gt; &lt;/td&gt;
          &lt;td&gt;    &lt;%=resultset.getString(3)%&gt;  &lt;/td&gt;
                  &lt;td&gt;     
                      Blob getimg=rs.getBlob( 4);
        InputStream readImg = getimg.getBinaryStream();
        int size=readImg.available();
        OutputStream outf=new FileOutputStream("D:/profile/"+rs.getString(2)+rs.getString(3)+".jpeg");
  
        byte b[]= new byte[size];
              readImg.read(b);
              outf.write(b);
              outf.close();
  
  
  
          &lt;/td&gt;
  
      &lt;/tr&gt;
      &lt;/table&gt;
  
  &lt;% }%&gt;
  
          &lt;/form&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>