Servlet response already use stream, Writer not possible
Abiodun Adisa
Ranch Hand
Joined: Jan 17, 2002
Posts: 495
posted
0
I am trying to obtain an image byte from the Session Context, Then i would like to display this image, The code segment is below
But unfortunately i am getting the following exception
Please how can i resolve this
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
Where is this code located - in a JSP page? I'm guessing it is, since you are posting to the JSP forum. A JSP page really can't (and shouldn't) use the output stream. If the response consists of an image you need move this code to a servlet.
Originally posted by Abiodun Adisa: I am trying to emit an image
Remember that a JSP is merely a template to deliver an HTML page to the browser. (See this article for details).
And to include an image in an HTML page, you don't embed image data, do you? No, you reference the image with an <img> tag.
So you need to do the same thing in your JSP. Include an <img> tag just as if it was an HTML page, specifying the URL of a servlet as the src of the <img> tag, that will feed up the image data.
Abiodun Adisa
Ranch Hand
Joined: Jan 17, 2002
Posts: 495
posted
0
Originally posted by Bear Bibeault:
Remember that a JSP is merely a template to deliver an HTML page to the browser. (See this article for details).
And to include an image in an HTML page, you don't embed image data, do you? No, you reference the image with an <img> tag.
So you need to do the same thing in your JSP. Include an <img> tag just as if it was an HTML page, specifying the URL of a servlet as the src of the <img> tag, that will feed up the image data.
JSP compilers will often add characters to the output stream going to the browser. Since the primary intent for JSP is textual output (Mainly HTML or XML) these characters aren't a problem. If you're trying to write binary data to a browser, however, they will become a problem. This is why it's best to do this with a servlet.
Thanks folks ,I used a servlet and it worked well. The code i earlier tried was straight from the myfaces example i downloaded from Myfaces. its contained in the file_upload.java file and it used a JSP to emit images which is wrong like you two gentlemen pointed out and this i agree with