For any given HTTP request the server returns a single response of a single
type. If you want to return test/html then that is what the server will
tell the browser it is returning and in turn, the browser will try to
display the data that way. If you want to return a byte stream like
image/jpeg then the browser expects just the bytes making up that stream and
no additional stuff like text. You should avoid mixing use of the
ServletOutputStream for different types of data. As for your include
problem you should avoid trying to do multiple things per request as the
Servlet API will often throw errors and if not, stuff will often still not
work the way you intended. I found a piece of code at our company in which
someone was trying to write to the ServletOutputStream but on an error they
would call the HttpServletResponse.sendRedirect(String) call. I don't
remember whether the servlet API explicitly threw an error but the code sure
didn't work as intended.
-Jamey
-----Original Message-----
From: Georges Boutros [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 17, 2001 11:43 AM
To: Tomcat (E-mail)
Subject: ServletOutputStream
hi,
i want to use the ServletOutputStream to send the data of a JPG image to the
browser.
ServletOutputStream ServletOut = response.getOutputStream();
it's working good but i can't write any text before or after the image.
if i set response.setContentType("text/html");
i see the text that i wrote and the data of the image as text
(which is normal)
and if i set response.setContentType("image/jpeg");
i don't see the text neither the Image
i use ServletOut.Print("hello"); to write my text
if i include a file with:
request.getRequestDispatcher("/jsp/web/test.jsp").include(request,
response);
i got an error that OutputStream is already being used for this request
can anyone help me
thanks
Georges