File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlet not printing image file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet not printing image file" Watch "servlet not printing image file" New topic

servlet not printing image file

Raj Puri
Ranch Hand

Joined: Apr 24, 2003
Posts: 189
I have a gif file in image directory under webapps/myapp/. The following code should print that gif file and does not. I played around with all combination of ptah to gif like ., ../.. etc nothing seems to work, however the message does print fine. Only image is missing. Can I print a gif file in this way from servlet?



PrintWriter out = response.getWriter();
out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");

out.println("<body bgcolor=\"white\">");
out.println("<img src=\"../../../images/show-calendar.gif\" width=24 height=22 border=0>");
out.println("<table style=\"border-style: double; 8px; border-color: 007FFF;\" cellspacing=\"10\" width=\"300\" align=\"center\" valign=\"top\" >");

out.println("<span class=\"bnew\">Report Encountered Error, Please Make Note Of The Following And Hit Back Button To Continue:</span>");

e.printStackTrace(out); out.println("</td>");

Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
You do getWriter for charecter data. Try getOutputStream method instead!

Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
Also, set your content type to accomodate gif type. I am not sure of the correct one but search for different mimes types. You will get one for gif/jpeg.
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Also look at the ouput after your code has run. Does the tag look the way you intended it too?

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

What is the URL that you're using for your servlet?
[ February 17, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: servlet not printing image file
It's not a secret anymore!