title: Displaying image in jsp from database
body: <p>For the code below, i googled lots, but somehow i couldn't figure out the error.. with respect to "img src" tag. </p>
  
  <p>There might be silly mistake, but it would be great if someone could help me out.</p>
  
  <p>I have saved my images inside the image folder, which is placed inside the project folder...
  the database has the image url under "image" attribute... so i am trying to retrieve the url from the database through <code>&lt;%=rs.getString("image") %&gt;</code> is that correct ?</p>
  
  <pre><code>&lt;html&gt;
   &lt;body&gt;
     &lt;%@ page import="java.io.*"%&gt;
     &lt;%@ page import="java.sql.*"%&gt;
     &lt;%@ page import="com.mysql.*"%&gt;
     &lt;%@ page import="java.util.*"%&gt;
     &lt;%@ page import="java.text.*"%&gt;
     &lt;%@ page import="javax.servlet.*"%&gt;
     &lt;%@ page import="javax.servlet.http.*"%&gt;
     &lt;%@ page import="javax.servlet.http.HttpSession"%&gt;
     &lt;%@ page language="java"%&gt;
     &lt;%@ page session="true"%&gt;
     &lt;%@ page import="java.sql.*"%&gt;
  &lt;% 
  Blob image = null;
  Connection con = null;
  Statement stmt = null;
  ResultSet rs = null;
  String iurl1=null;
  
  try {
      Class.forName("com.mysql.jdbc.Driver");
      con =           DriverManager.getConnection("jdbc:mysql://localhost:portnumber/dbname","","");
      stmt = con.createStatement();
      rs = stmt.executeQuery("select * from tablename where id = 1");
  }
  catch (Exception e) {
      out.println("DB problem"); 
      return;
  }
  finally {
      try {
          rs.close();
          stmt.close();
          con.close();
      }
      catch (SQLException e) {
          e.printStackTrace();
      }
  }
  %&gt;
      &lt;table border="2"&gt;
       &lt;tr&gt;&lt;th&gt;DISPLAYING IMAGE&lt;/th&gt;&lt;/tr&gt;
       &lt;tr&gt;&lt;td&gt;Image 2&lt;/td&gt;&lt;/tr&gt;
       &lt;tr&gt;
         &lt;td&gt;
           &lt;img src="&lt;%=rs.getString("image") %&gt;" width="500" height="500"/&gt;
         &lt;/td&gt;
       &lt;/tr&gt;
      &lt;/table&gt;
  
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>