Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Image Blob  RSS feed

 
Rene Ribeiro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Morning,

I have a class that is listing data, and these data have image.
How do I display the image in the JSP?









 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a servlet that gets the blob then streams the image back.

You will need an <img> tag on the JSP referncing back to the servlet.
Something like:

<img src="link to servlet that fetches the image, with parameters to identify the image">
 
Rene Ribeiro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My servlet looked like this, but as I will identify by the ID image in JSP?


CustomerDAO objCustomerDAO = new CustomerDAO();
Customer objCustomer = new Customer();

objCustomerDAO.listarCustomer();

List<Customer> listing = objCustomerDAO.listCustomer;

request.getSession().setAttribute("name", objCustomer.getName());

request.getSession().setAttribute("img", objCustomer.getImage());

request.setAttribute("listCustomer", listing);
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to handle the image as a separate call.

This all comes down to how images work in HTML.

First the browser requests the page (your current JSP).
The server returns that page.
Then the browser requests all the other bits for the page, eg Javascript files...and images, from the <img> tag.

So your current JSP needs an <img> tag, as I suggested earlier.
That points to another servlet whose job is to stream the image back.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!