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
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. InputStream.read(byte, int, int) doesn't necessarily need to read as much as you want. You should use a loop for reading and writing.