1

I have content of an image in a byte array, in a jetty servlet class. How could I display this image in a browser?

0

2 Answers 2

4

You will have something similar to this inside your sevlet

byte[] imageBytes = ...
response.setHeader("Content-Type", "image/jpg");// or png or gif, etc
response.setHeader("Content-Length", imageBytes.lenght);
response.getOutputStream().write(imageBytes);
Sign up to request clarification or add additional context in comments.

Comments

1

This code worked. Thanks to "David Hofmann".

//data is the content of the image in binary
response.setContentType("image/jpg");// or png or gif, etc
response.setContentLength(data.length);
response.getOutputStream().write(data);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.