0

The following servlet code,gets the image bytes from the database's table.

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Configuration config = new Configuration().configure();
    SessionFactory sessFact = config.buildSessionFactory();
    Session sess = sessFact.openSession();
    pojo.File image_file = (pojo.File)sess.get(pojo.File.class, 2);
    byte image_file_bytes[] = image_file.getFiles_uploaded(); 

    // NOW WHAT ? HOW DO I MAKE IT DISPLAY IN THE BROWSER ?
}

I have the bytes. What do I do next to display image on to the browser ?

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
  • 2
    Check what happens when you set the `response` header and write the bytes to the `ServletoutputStream` ! – AllTooSir Jun 07 '13 at 07:30
  • try this [Convert byte array (byte[]) to Image in Java][1] [1]: http://stackoverflow.com/questions/7119472/convert-byte-array-byte-to-image-in-java – Shujaat Abdi Jun 07 '13 at 07:32
  • try this [Convert byte array (byte[]) to Image in Java][1] [1]: http://stackoverflow.com/questions/7119472/convert-byte-array-byte-to-image-in-java – Shujaat Abdi Jun 07 '13 at 07:34

1 Answers1

1

You use the OutputStream of the HttpServletResponse to write the data out.

Moritz Petersen
  • 12,902
  • 3
  • 38
  • 45