Solved

tomcat and outputting a GIF

Posted on 2006-07-21
3
286 Views
Last Modified: 2013-11-24
Hi,

I have a servlet that i would like to use to output images.

The problem is, when I output the image as a string, it doesnt render ('The image 'http://.../' cannot be displayed because it contains errors).

If i also send the image to a file, I get a renderable image.

This is the code that I am trying to use with no luck:
   response.setContentType("image/gif");
   PrintWriter out = response.getWriter();
   out.println(new String[]{image});

where image is a byte[]. If i look at the source for the page, I actually see the textual representation of the gif.

Any ideas of how to get this to display properly?

Thanks.
0
Comment
Question by:kawas
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
Comment Utility
You need to do

response.setContentType("image/gif");
OutputStream out = response.getOutputStream();

and write the image to that
0
 
LVL 13

Author Comment

by:kawas
Comment Utility
thanks a lot.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:-)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
java continue statement 10 70
pairstar challenge 2 41
pairs challenge 5 44
Eclipse Neon and jdk 1.8.0 11 63
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now