• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

displaying image in jsp from sql using helper servlet

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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




 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Why are you doing this?
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic