• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to pass the image from servlet to jsp

 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
i am getting the image from database now i want to send the image from the sevlet to jsp page...how to do this...
give me solution.....
thank you,
Anil
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't say in which form you have the image in your code, but any Java object can be passed from a servlet to JSP by using HttpServletRequest.setAttribute.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done this before. Basically you need to have an img tag in your html/jsp file that uses an action for the src. Instead of "/app/myimage.jsp" you would use "/app/DisplayImage.do?id=123". Your DisplayImage action would pull the image out of the database and stream the contents to the response. Your action would then return null from the execute method. I do not have the source code handy, but I could probably dig it up.

- Brent
 
Chris Boldon
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sample code from one of my sites:



Hope it helps!
 
Samir Bukkawar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have an Image object which is created in java.awt.Image format in my servlet.
can you please give me any idea or small code so that I can display this image in my JSP page.

I would appreciate any information.
Thanks in advance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic