File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes how to pass the image from servlet to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to pass the image from servlet to jsp" Watch "how to pass the image from servlet to jsp" New topic

how to pass the image from servlet to jsp

Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155
i am getting the image from database now i want to send the image from the sevlet to jsp to do this...
give me solution.....
thank you,
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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

Joined: Feb 08, 2006
Posts: 948
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/". 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

Joined: Aug 10, 2006
Posts: 190
Sample code from one of my sites:

Hope it helps!
Samir Bukkawar

Joined: May 15, 2009
Posts: 5
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.
I agree. Here's the link:
subject: how to pass the image from servlet to jsp
It's not a secret anymore!