title: How to return image using a /get route on Spark Java so it displays on the webpage?
body: <p>As the title says, I am trying to display an image on a webpage using Spark Java. The image I am trying to retrieve was stored as a MEDIUMBLOB using mysql. </p>
  
  <pre><code>    File file = new File("image.jpg");
      FileOutputStream output = new FileOutputStream(file);
      BufferedImage bi = null;
          System.out.println("Writing to File: " + file.getAbsolutePath());
          try {
  
  
              String sql = "SELECT Image FROM images WHERE Image_ID = 0;";
              PreparedStatement statement = db.conn.prepareStatement(sql);
              ResultSet rs = statement.executeQuery();
              //writes image to file to make sure it the image come out right
              while(rs.next()){
                  InputStream input = rs.getBinaryStream("Image");
                  bi = ImageIO.read(input);
                  int available = input.available();
                  byte[] buffer = new byte[available];
                  while(input.read(buffer) &gt; 0){
                      output.write(buffer);
                  }
              }
  
  
  
              } catch (Exception e) {
              System.out.println(e);
          }
  
  
  
      return bi;
  </code></pre>
  
  <p>I am using a HTML form to call the function:</p>
  
  <pre><code>    &lt;div class="get_file"&gt;
          &lt;form method="get" action="/mainpage"&gt;
              &lt;input type = "submit"&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>When I run the program, instead of displaying the image it just gives me this text: </p>
  
  <blockquote>
    <p>BufferedImage@4b72a5d2: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 >color space = java.awt.color.ICC_ColorSpace@68f38796 transparency = 1 has alpha >= false isAlphaPre = false ByteInterleavedRaster: width = 274 height = 184 >#numDataElements 3 dataOff[0] = 2</p>
  </blockquote>