title: Blob Images are not displaying in jsp page [struts 1]
body: <p>I am using netbeans 6.9 and i am a beginner in the struts 1.3.8 and I did not know how to display the product image in the jsp page. I added the images in images folder under the web folder and store the images names in the database as blob and when I am retrieving the image from database it just prints me the name of the image.</p>
  
  <p>this is the jsp page: </p>
  
  <pre><code>&lt;html:form action="/addToCartAction"&gt;
          &lt;span style='color:red'&gt;&lt;html:errors property="SQL" /&gt;
              &lt;html:errors property="SQLException" /&gt;&lt;/span&gt;
          &lt;table border="0"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;&lt;/th&gt;
                      &lt;th&gt;&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;td rowspan="6"&gt;&lt;bean:write name="userHomeForm" property="itemImage" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;bean:write name="userHomeForm" property="itemName" /&gt;
  
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;item in stock: &lt;bean:write name="userHomeForm" property="itemQyt" /&gt;
  
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;AED&lt;bean:write name="userHomeForm" property="itemPrice" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;bean:write name="userHomeForm" property="itemDesc" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;html:text property="number" value="" size="3"/&gt;&amp;nbsp;
                          &lt;input type="hidden" name="itemID" value="${userHomeForm.itemID}"/&gt;
                          &lt;input type="hidden" name="itemQyt" value="${userHomeForm.itemQyt}"/&gt;
                          &lt;html:submit value="add to cart"/&gt;&lt;/td&gt;                        
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;span style='color:red'&gt;&lt;html:errors property="Qyt"/&gt;&lt;html:errors property="OverQyt"/&gt;&lt;/span&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
              &lt;/tbody&gt;
          &lt;/table&gt;
  
  
      &lt;/html:form&gt;
  </code></pre>
  
  <p>this is the bean:</p>
  
  <pre><code>public class userHomeForm extends org.apache.struts.action.ActionForm {
  
  private ArrayList result;
  private String category;
  private String brand;
  //// item info
  private Integer itemID;
  private Integer categoryID;
  private Integer brandID;
  private Integer itemQyt;
  private Integer itemPrice;
  private String itemImage;
  private String itemName;
  private String itemDesc;
  
  
  public Integer getBrandID() {
      return brandID;
  }
  
  public void setBrandID(Integer brandID) {
      this.brandID = brandID;
  }
  
  public Integer getCategoryID() {
      return categoryID;
  }
  
  public void setCategoryID(Integer categoryID) {
      this.categoryID = categoryID;
  }
  
  public String getItemDesc() {
      return itemDesc;
  }
  
  public void setItemDesc(String itemDesc) {
      this.itemDesc = itemDesc;
  }
  
  public Integer getItemID() {
      return itemID;
  }
  
  public void setItemID(Integer itemID) {
      this.itemID = itemID;
  }
  
  public String getItemImage() {
      return itemImage;
  }
  
  public void setItemImage(String itemImage) {
      this.itemImage = itemImage;
  }
  
  public String getItemName() {
      return itemName;
  }
  
  public void setItemName(String itemName) {
      this.itemName = itemName;
  }
  
  public Integer getItemPrice() {
      return itemPrice;
  }
  
  public void setItemPrice(Integer itemPrice) {
      this.itemPrice = itemPrice;
  }
  
  public Integer getItemQyt() {
      return itemQyt;
  }
  
  public void setItemQyt(Integer itemQyt) {
      this.itemQyt = itemQyt;
  }
  
  
  public String getBrand() {
      return brand;
  }
  
  public void setBrand(String brand) {
      this.brand = brand;
  }
  
  public String getCategory() {
      return category;
  }
  
  public void setCategory(String category) {
      this.category = category;
  }
  
  public ArrayList getResult() {
      return result;
  }
  
  public void setResult(ArrayList result) {
      this.result = result;
  }
  /**
   *
   */
  public userHomeForm() {
      super();
      // TODO Auto-generated constructor stub
  }
  </code></pre>
  
  <p>this is the action :</p>
  
  <pre><code>public class userHomeAction extends org.apache.struts.action.Action {
  
  /* forward name="success" path="" */
  private static final String SUCCESS = "success";
  private final static String FAILURE = "failure";
  // Initialize SQL connection equal null
  private Connection con = null;
  private ResultSet rst = null;
  private ResultSet rs = null;
  
  /**
   * This is the action called from the Struts framework.
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   * @throws java.lang.Exception
   * @return
   */
  @Override
  public ActionForward execute(ActionMapping mapping, ActionForm form,
          HttpServletRequest request, HttpServletResponse response)
          throws Exception {
      //Initilized Action error
      ActionErrors errors = new ActionErrors();
      // set the session on in the page
      HttpSession session = request.getSession(true);
      //Call userHomeForm Instance here
      userHomeForm formBean = (userHomeForm) form;
      // extract user data
      String category = formBean.getCategory();
      String brand = formBean.getBrand();
  
      //Set up flag message
      boolean searchFlag = false;
  
      // perform validation
      if (category == null ||         // category parameter does not exist
          category.equals("") ||      // category parameter is empty
          category.length()&lt; 1){      // category parameter is empty
          errors.add("category", new ActionMessage("errors.category.required"));
      }
      if (brand != null &amp;&amp;            // brand parameter does not exist
          brand.equals("") &amp;&amp;         // brand parameter is empty)
          brand.length()&lt; 1) {        // brand parameter is empty)
          errors.add("brand", new ActionMessage("errors.brand.required"));
      }
      //Save error messages keys into the appropriate HTTP request attribute for use by the &lt;html:errors&gt; tag
      saveErrors(request, errors);
      //Check- is errors empty
      if (errors.isEmpty()) {
          searchFlag = true;
  
          // start Viewing userHome
          System.out.println("////////////////////////// start Viewing userHome  /////////////////////////");
  
      } else {
          searchFlag = false;
      }
  
      // Now Start communicate with database
      try {
          Class.forName("com.mysql.jdbc.Driver").newInstance();
          con = DriverManager.getConnection("jdbc:mysql://localhost:3306/gsm", "root", "root");
          //ArrayList&lt;String[]&gt; result = new ArrayList&lt;String[]&gt;();
          PreparedStatement ps = (PreparedStatement) con.prepareStatement("select * from item where categoryID=? and brandID=?");
          ps.setString(1, category);
          ps.setString(2, brand);
          rs = ps.executeQuery();
          Blob img= null;
          byte[]imgData= null;
          int columnCount = rs.getMetaData().getColumnCount();            
          int num = 0;
          if (rs != null) // Succes
          {
              while (rs.next()) {
                  num++;
                  searchFlag = true;
                  int categoryID = rs.getInt("categoryID");
                  int brandID = rs.getInt("brandID");
                  int itemID = rs.getInt("itemID");
                  int itemQyt = rs.getInt("itemQyt");
                  int itemPrice = rs.getInt("itemPrice");
                  String itemName = rs.getString("itemName");
                  String itemDesc = rs.getString("itemDesc");
                  String itemImage = rs.getString("itemImage");
                  formBean.setBrandID(brandID);
                  formBean.setCategoryID(categoryID);
                  formBean.setItemDesc(itemDesc);
                  formBean.setItemID(itemID);
                  formBean.setItemImage(itemImage);
                  formBean.setItemName(itemName);
                  formBean.setItemPrice(itemPrice);
                  formBean.setItemQyt(itemQyt);
                  //// check out
                  System.out.println("The item is from the category which its ID is : " + categoryID + " and brand with id :" + brandID + " and the item id is : " + itemID + " and with name : " + itemName + " and its price is : " + itemPrice + " with that much quantity : " + itemQyt + " and its description is : " + itemDesc);
  
              }                               
          }                       
      } catch (Exception ex) {
          errors.add("SQLException", new ActionMessage("errors.SQLException"));
          throw new SQLException(ex.fillInStackTrace());
      }
      //Close SQL server connection
      try {
          if (con != null) {
              con.close();
          }
      } catch (SQLException e) {
          throw new SQLException(e.getSQLState() + e.fillInStackTrace());
      }
      //Save error messages keys into the appropriate HTTP request attribute for use by the &lt;html:errors&gt; tag
      saveErrors(request, errors);
      if (errors.isEmpty()) {
          searchFlag = true;
      } else {
          searchFlag = false;
      }
  
      if (searchFlag) {
      return mapping.findForward(SUCCESS);
      } else {
  
          return mapping.findForward(FAILURE);
      }
  
  }
  </code></pre>
  
  <p>}</p>