title: Displaying an image and a text with Spring MVC (from database)
body: <p>I want to display an image <strong>AND</strong> a String using Spring MVC 3.
  Both are instance variables of a POJO that I retreive from the database using Hibernate.</p>
  
  <pre><code>@Entity
  @Table(name = "document")
  public class Document {
  
      //id        
  
      @Column(name = "name")
      private String name;  // the String
  
      @Basic(fetch = FetchType.LAZY)
      @Column(name="content")
      private byte [] image;
  //getters setters
  </code></pre>
  
  <p>I want to display the image on the .jsp page using Spring MVC 3 <strong>AND</strong> display the String next to it.
  Currently I can display <strong>ONLY</strong> the picture by streaming it and printing the String to the console but it is not what I want. (Of course I can display the String, but if I display the String, then I am not able to display the image.) <strong>I want to display both,</strong> on the same page, next to eachother.</p>
  
  <pre><code>@RequestMapping(value = "/displayDocument", method = RequestMethod.POST)
      public void displayDocument(@RequestParam("documentId") String documentId, HttpServletResponse response) {
  
          Document doc = documentService.get(Long.valueOf(documentId));
  
          System.out.println(doc.getName());
  
          if (doc.getImage() != null) {
              response.setContentType("image/jpg");
              try {
                  response.getOutputStream().write(doc.getImage());
                  response.getOutputStream().flush();
                  response.getOutputStream().close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  
      }
  </code></pre>
  
  <p>I do not want to beleive that there isn't any clever solution to acheive this....</p>