Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Display Image in JSP retrieved from database by servlet

Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi... I have a servlet that is getting an image from the database. After getting image I want to display it in a JSP page. But web page is not displaying the image. Servlet is working fine in my opinion, because when I run the servlet it shows me dialog box to save the image and I am able to save the image successfully. Please help me asap. Thanxs
............This is the servlet............

This is img tag by which I am trying to display the image

<img src="/Servlet/DBImage" alt="My image" height="200px" width="200px">
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML IMG tag requests always use the GET method - why did you use doPost?

What is the idea behind these statements?

Posts: 21997
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) You should write only the image contents, nothing else (so no HTML, HEAD or BODY tags).
2) You should not read a binary image as a String. Binary data can usually not be displayed in Strings.
3) You should never ever ever ever trust anything that comes from the user. Use PreparedStatement to prevent SQL injection.
4) Your way of writing is flawed.[], int, int) doesn't necessarily need to read as much as you want. You should use a loop for reading and writing.
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi, Where are you passing the request parameter named "value". The link img src="/Servlet/DBImage does not seem to pass any request parameter to your Servlet.
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic