title: How to display an image in jsp?
body: <p>I have a bytearray image. </p>
  
  <p>I need to show that image in jpg format in jsp page and while clicking the image, i can download the image to my pc: </p>
  
  <p>I am loading the image from my mysql db as byte array..</p>
  
  <p>My code is </p>
  
  <pre><code>     ResultSet res = statement.executeQuery("SELECT * FROM 
     upload_data where user_id = "+userID);
     while (res.next()) {
  
   contactDetails = new ContactDetails();
  
  contactDetails.setContactPhoto(res.getBytes("photo"));
  
  byteArrayBackToImage1(res.getBytes("photo"));
   contactsList.add(contactDetails);
  }
  
  public void byteArrayBackToImage1(byte[] imageInByte){
  try{
  
       Random rand = new Random();
          int numNoRange = rand.nextInt();
          String number = String.valueOf(numNoRange);
      //convert byte array back to BufferedImage
  
  
      InputStream in = new ByteArrayInputStream(imageInByte);
      BufferedImage bImageFromConvert = ImageIO.read(in);
      System.out.println("bImageFromConvert : "+bImageFromConvert);
  
      /*ImageIO.write(bImageFromConvert, "jpg", 
               new File("c:\\"+number+".jpg")); */
  
  
  }catch (Exception e) {
      // TODO: handle exception
  }
  </code></pre>
  
  <p>I need to show the image in jsp as </p>
  
  <p>eg:  image.jpg
       image2.jpg</p>
  
  <p>and by clicking image.jsp , i can download that image and save it to my pc</p>
  
  <p>Please help</p>