Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

display image on sturts from data base  RSS feed

 
vikassheel gupta
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i have a problem reated to image retrieval what i did till now i have a column in data base with blob data type
I can easily upload the image with the help of FormFile and BinaryStream but when i try to retrieve that image i face some sort of problem My problem is:--

I got the image in the resultset with the help of connection but its return type is InputStream which doesnt have the write method so that i can not write that image in the jsp page

if i didnt use InputStream and i use byte array and then try to print it again it will not print with no error so i cant not understand why this problem occurs
thanks alot
 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to have to "write" the image to a file, and include the path to that file from your page. Try writing to a file first, once you get that you'll see that all you need to do then is include the path to this within an image tag.

Additionally, you might want to check this forum form more on I/O issues.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way of approaching this would be to write a servlet or struts action class that does the following:
  • get the OutputStream from the HttpServletResponse object using the getOutputStream() method
  • read the input stream and write it to the OutputStream
  • close the OutputStream and if this is a Struts Action, return a null forward
  • in your jsp, use src="myAction.do" in your <img> tag


  • In the Struts 1.2.x download, the struts-examples.war file that comes with the download contains an example of how to do this. Look for org.apache.struts.webapp.exercise.ImageAction
    [ October 19, 2005: Message edited by: Merrill Higginson ]
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!