Suhail Gupta
Suhail Gupta

Reputation: 23276

How do I display images on the browser submitted to the database?

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 ?

Upvotes: 0

Views: 84

Answers (1)

Moritz Petersen
Moritz Petersen

Reputation: 13057

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

Upvotes: 1

Related Questions