title: How to display image from mysql database using spring mvc
body: <p>I am storing BLOB type image in MySQL database using Spring MVC for item class Item (itemId, itemName, itemPrice, itemContent, itemImage). I successfully stored image in database but when I'm trying to display it in my jsp, it is showing something binary like [B@7fb0c025.</p>
  
  <p>How can I display proper image in JSP (image is stored in MySQL database table)</p>
  
  <p>My model class:</p>
  
  <pre><code>@Entity
  @Table(name="item")
  public class Item {
  
  @Id
  @Column(name="ItemId")
  @GeneratedValue
  private Integer itemId;
  
  @Column(name="ItemName")
  private String itemName;
  
  @Column(name="ItemContent")
  private String itemContent;
  /*
  @Column(name="ItemImage")
  private ByteArray ItemImage;
  */
  @Column(name="ItemPrice")
  private int itemPrice;
  
  @Column(name="ItemImage")
  private byte[] itemImage;
  </code></pre>
  
  <p>"addItem.jsp" to add item attributes along with the image in database.</p>
  
  <pre><code>&lt;form:form modelAttribute="itemAttribute" enctype="multipart/form-data" method="POST" action="${Url}"&gt;
  &lt;table&gt;
  
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="itemId"&gt;&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="itemId" type="hidden"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="itemName"&gt;ItemName:&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="itemName"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="itemPrice"&gt;ItemPrice:&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="itemPrice"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="itemContent"&gt;ItemContent:&lt;/form:label&gt;
          &lt;td&gt;&lt;form:input path="itemContent"/&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;form:label for="itemImage" path="itemImage"&gt;itemImage:&lt;/form:label&gt;
          &lt;form:input path="itemImage" type="file" /&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;input type="submit" value="Save" /&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>The JSP page to display item attributes along with the image.
      
      
          
              CategoryId:
              
          </p>
  
  <pre><code>    &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="categoryName"&gt;CategoryName:&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="categoryName"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" value="Save" /&gt;
  
  &lt;table width: 100%; text-align:center"&gt;
  &lt;tr&gt;
      &lt;th&gt;ItemId&lt;/th&gt;
      &lt;th&gt;ItemName&lt;/th&gt;
      &lt;th&gt;ItemPrice&lt;/th&gt;
      &lt;th&gt;ItemFeatures&lt;/th&gt; 
      &lt;th&gt;Edit&lt;/th&gt;
      &lt;th&gt;Delete&lt;/th&gt;
      &lt;th&gt;ItemImage&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tbody&gt;
  
  
      &lt;c:forEach items="${categoryAttribute.item}" var="item"&gt;
      &lt;tr&gt;
              &lt;c:url var="editCUrl" value="/item/edit?bid=${categoryAttribute.categoryId}&amp;cid=${item.itemId}" /&gt;
              &lt;c:url var="deleteCUrl" value="/item/delete?id=${item.itemId}" /&gt;
              &lt;td&gt;&lt;c:out value="${item.itemId}" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${item.itemName}"/&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${item.itemPrice}"/&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${item.itemContent}"/&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href="${editCUrl}"&gt;EditItem&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href="${deleteCUrl}"&gt;DeleteItem&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${item.itemImage}"/&gt;&lt;/td&gt;
      &lt;/tr&gt;   
      &lt;/c:forEach&gt;
  </code></pre>
  
  <p>How can I properly display the image which is stored in the database? I guess I'm doing it wrong by displaying image like this in JSP.
      
  But how can I display the image here in JSP?</p>