This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I receive an image as byte array (byte) from a servlet to a jsp page and i'm trying
to display this image in the jsp.
How should I do that ? How should I transfer this byte to image which I can see in the jsp page ?
Handling binary data should be left to the servlet; JSPs are meant for textual output (like HTML).
The two ways I see are a) store the byte as a file with a known name, and then use that filename in the the img tag of a JSP page, or b) keep the data in memory (maybe as a session or application attribute), and have a servlet stream it to the client (with the servlet's URL in the image tag's "src" attribute).
As Ulf has pointed out, you've put the cart before the horse.
Remember that all a JSP is is a way to create an HTML page to send the browser. And when putting an image into an HTML page do you embed binary data? Of course not. You create an image tag that references a resource (usually an image file) that serves the binary data.
Same thing here. You shouldn't be fetching the image data at all in the request that generates the JSP. Rather, create an image tag on the JSP that references a different servlet that serves up the binary data when asked for it.