• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying image in jsp from sql using helper servlet

 
ekansh singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am struck on a simple problem
I have to display an image from a database. I have successfully uploaded the image in database.
now for displaying image on JSP I have a servlet which is doing this work

This servlet is stored in src folder under package action. Actually I am using struts2 and i dont know how to display it using struts2.
So my servlet is like this


getImage functionality is like this


}
[/code]

On JSP my code is


on searching on net i found this also

i tried using both but I am unable to display the image




 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64724
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When hitting the servlet directly in the browser displays the image, it will work from an <img> tag in an HTML page.

So work on your servlet -- make sure that it returns the right data and has the correct response headers set.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64724
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why are you doing this?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ekansh singh wrote:Actually I am using struts2 and i dont know how to display it using struts2.
This is irrelevant. Struts is just another MVC framework.

i tried using both but I am unable to display the image

Aside from a lot of logic faults and resource leaks I see two huge flaws: 1) you're calling super.doGet() in the servlet and 2) you're getting only the first 20000 bytes of an image and ignoring the rest in the DAO.

Check the 2nd example of this article how to do it properly: http://balusc.blogspot.com/2007/04/imageservlet.html
As a suggestion, first test the image independently in your webbrowser without using HTML <img> element.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic