RE: [ERROR] OutputStream is already being used for this request
Hi I can not call the servlet directly because I need to show the image as part of the html page Tali Yeah, you will have to also make sure to set the content-type to image/GIF in your %@ page ...% tag (I forget exact syntax right now). Otherwise, there will be a problem when content-type headers are sent twice: once from the JSP page, and then again from the servlet. -Mark [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] On Wed, 2 May 2001, CPC Livelink Admin wrote: Why do you need to use a JSP - The JSP is designed to product HTML output, and as such will always grab the writer and set the content type to text/html. What is wrong with just using the servlet, perhaps with an extention mapping . . . -Original Message- From: Tali Ambar [mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 02, 2001 2:12 AM To: '[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]' Subject: FW: [ERROR] OutputStream is already being used for this request Hi 1. I'm trying to pass a stream to an html in order to see GIF files in a stream form on the browser. 2. I wrote (in a servlet) the following lines IStream stream = ...; // stream of a file in a GIF format response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); 3. This servlet is called by a jsp which is called from an Html file (by the tag: img src=myJsp.jsp ) 4. When running only the servlet I can see the GIF file. 5. When I run the jsp I get the following error: Error 500: OutputStream is already being used for this request at org.apache.tomcat.core.ResponseImpl.getWriter(ResponseImpl.java:210) 6. running the html file fails 7. I can not use PrintWriter servlet because I need to pass binary data and not test. Thanks Tali
RE: [ERROR] OutputStream is already being used for this request
Your best bet is to call the servlet directly. I agree with the other responders that suggest that using a jsp to dispatch a request to a servlet that generates a non-html/text/wml/xml document should be avoided. If you *have* to do so, then your jsp must be setup in an awkward way. related to your step 3: 3. This servlet is called by a jsp which is called from an Html file (by the tag: img src=myJsp.jsp) At some point in your myJsp.jsp, you are including the content of or forwarding to the servlet, correct? I'm assuming the method you are using is either jsp:include|forward ..., or pageContext.include|forward(). If this is the case, then... All of the proper headers must be sent from the dispatching jsp file (myJsp.jsp), and none from the servlet. I believe the jsp file will always send response headers, and it is definitely an error to commit the headers twice. No output can be sent from the jsp file at all prior to dispatching to the servlet, else a JspWriter might have been opened. It would then generate an error. As an example, create a myJsp.jsp file that has no other characters other than: % @ page content-type=image/GIF %jsp:forward page=myJsp.jsp (again, check the page tag for correct syntax, I still haven't referenced the cheat sheet) and coment out the following line in your servlet: //response.setContentType (image/GIF); The point is, that there are no white spaces that might cause output. This is an ugly hack, and as another responder suggested, it is easily broken by somebody putting white space in the file before the jsp:forward tag. All of that said, you should really consider calling the servlet directly if at all possible. -Mark [EMAIL PROTECTED] On Wed, 2 May 2001, Tali Ambar wrote: I do not use pageContext.forward(..) or .include(..) and there aren't any % written the following code is written in a Servlet: response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); I thought that they might be some flag which can dim the PrintWriter out and then I could pass the outtputStream to the client side. Thanks Tali -Original Message- You might need to make sure that no output is being sent to the browser prior to your attempting to open the outputStream. ANY spaces before the pageContext.forward(..) or .include(..) call may be sent to the browser and will create a JspWriter output stream that will conflict with your getOutputStream() call. One thing worth trying is to start your jsp file with the first characters %, the scriptlet openning tag, and make the call to the servlet before any output is generated in your jsp file. I hope that helps, -Mark [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] On Wed, 2 May 2001, Tali Ambar wrote: Hi 1. I'm trying to pass a stream to an html in order to see GIF files in a stream form on the browser. 2. I wrote (in a servlet) the following lines IStream stream = ...; // stream of a file in a GIF format response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); 3. This servlet is called by a jsp which is called from an Html file (by the tag: img src=myJsp.jsp ) 4. When running only the servlet I can see the GIF file. 5. When I run the jsp I get the following error: Error 500: OutputStream is already being used for this request at org.apache.tomcat.core.ResponseImpl.getWriter(ResponseImpl.java:210) 6. running the html file fails 7. I can not use PrintWriter servlet because I need to pass binary data and not test. Thanks Tali
RE: [ERROR] OutputStream is already being used for this request
I do not use pageContext.forward(..) or .include(..) and there aren't any % written the following code is written in a Servlet: response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); I thought that they might be some flag which can dim the PrintWriter out and then I could pass the outtputStream to the client side. Thanks Tali -Original Message- You might need to make sure that no output is being sent to the browser prior to your attempting to open the outputStream. ANY spaces before the pageContext.forward(..) or .include(..) call may be sent to the browser and will create a JspWriter output stream that will conflict with your getOutputStream() call. One thing worth trying is to start your jsp file with the first characters %, the scriptlet openning tag, and make the call to the servlet before any output is generated in your jsp file. I hope that helps, -Mark [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] On Wed, 2 May 2001, Tali Ambar wrote: Hi 1. I'm trying to pass a stream to an html in order to see GIF files in a stream form on the browser. 2. I wrote (in a servlet) the following lines IStream stream = ...; // stream of a file in a GIF format response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); 3. This servlet is called by a jsp which is called from an Html file (by the tag: img src=myJsp.jsp ) 4. When running only the servlet I can see the GIF file. 5. When I run the jsp I get the following error: Error 500: OutputStream is already being used for this request at org.apache.tomcat.core.ResponseImpl.getWriter(ResponseImpl.java:210) 6. running the html file fails 7. I can not use PrintWriter servlet because I need to pass binary data and not test. Thanks Tali
RE: [ERROR] OutputStream is already being used for this request
I do not use pageContext.forward(..) or .include(..) and there aren't any % written the following code is written in a Servlet: response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); I thought that they might be some flag which can dim the PrintWriter out and then I could pass the outtputStream to the client side. Thanks Tali -Original Message- You might need to make sure that no output is being sent to the browser prior to your attempting to open the outputStream. ANY spaces before the pageContext.forward(..) or .include(..) call may be sent to the browser and will create a JspWriter output stream that will conflict with your getOutputStream() call. One thing worth trying is to start your jsp file with the first characters %, the scriptlet openning tag, and make the call to the servlet before any output is generated in your jsp file. I hope that helps, -Mark [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] On Wed, 2 May 2001, Tali Ambar wrote: Hi 1. I'm trying to pass a stream to an html in order to see GIF files in a stream form on the browser. 2. I wrote (in a servlet) the following lines IStream stream = ...; // stream of a file in a GIF format response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); 3. This servlet is called by a jsp which is called from an Html file (by the tag: img src=myJsp.jsp ) 4. When running only the servlet I can see the GIF file. 5. When I run the jsp I get the following error: Error 500: OutputStream is already being used for this request at org.apache.tomcat.core.ResponseImpl.getWriter(ResponseImpl.java:210) 6. running the html file fails 7. I can not use PrintWriter servlet because I need to pass binary data and not test. Thanks Tali
RE: [ERROR] OutputStream is already being used for this request
I do not use pageContext.forward(..) or .include(..) and there aren't any % written the following code is written in a Servlet: response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); I thought that they might be some flag which can dim the PrintWriter out and then I could pass the outtputStream to the client side. Thanks Tali -Original Message- You might need to make sure that no output is being sent to the browser prior to your attempting to open the outputStream. ANY spaces before the pageContext.forward(..) or .include(..) call may be sent to the browser and will create a JspWriter output stream that will conflict with your getOutputStream() call. One thing worth trying is to start your jsp file with the first characters %, the scriptlet openning tag, and make the call to the servlet before any output is generated in your jsp file. I hope that helps, -Mark [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] On Wed, 2 May 2001, Tali Ambar wrote: Hi 1. I'm trying to pass a stream to an html in order to see GIF files in a stream form on the browser. 2. I wrote (in a servlet) the following lines IStream stream = ...; // stream of a file in a GIF format response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); 3. This servlet is called by a jsp which is called from an Html file (by the tag: img src=myJsp.jsp ) 4. When running only the servlet I can see the GIF file. 5. When I run the jsp I get the following error: Error 500: OutputStream is already being used for this request at org.apache.tomcat.core.ResponseImpl.getWriter(ResponseImpl.java:210) 6. running the html file fails 7. I can not use PrintWriter servlet because I need to pass binary data and not test. Thanks Tali
Re: [ERROR] OutputStream is already being used for this request
That is probably the same kind of problem as the one I mentioned yesterday (GZIPOutputStream, JSP, servlets) : Your response.setContentType (image/GIF);ServletOutputStream outStream = response.getOutputStream(); sets useStream to true in the HttpResponseAdapter class. When your JSP is compiled, the JspWriterImpl class is used. When it first tries to write a line which exceeds the buffer size, it tries to get a PrintWriter, not an OutputStream, and a test is performed which is quite like this : if (useStream) { thow new IllegalStateException() } Should you get a solution, please let me know. Loïc QUERAN - Original Message - From: Tali Ambar [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 02, 2001 8:12 AM Subject: FW: [ERROR] OutputStream is already being used for this request Hi 1. I'm trying to pass a stream to an html in order to see GIF files in a stream form on the browser. 2. I wrote (in a servlet) the following lines IStream stream = ...; // stream of a file in a GIF format response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); 3. This servlet is called by a jsp which is called from an Html file (by the tag: img src=myJsp.jsp) 4. When running only the servlet I can see the GIF file. 5. When I run the jsp I get the following error: Error 500: OutputStream is already being used for this request at org.apache.tomcat.core.ResponseImpl.getWriter(ResponseImpl.java:210) 6. running the html file fails 7. I can not use PrintWriter servlet because I need to pass binary data and not test. Thanks Tali Email: [EMAIL PROTECTED]
RE: [ERROR] OutputStream is already being used for this request
Why do you need to use a JSP - The JSP is designed to product HTML output, and as such will always grab the writer and set the content type to text/html. What is wrong with just using the servlet, perhaps with an extention mapping . . . -Original Message- From: Tali Ambar [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 02, 2001 2:12 AM To: '[EMAIL PROTECTED]' Subject: FW: [ERROR] OutputStream is already being used for this request Hi 1. I'm trying to pass a stream to an html in order to see GIF files in a stream form on the browser. 2. I wrote (in a servlet) the following lines IStream stream = ...; // stream of a file in a GIF format response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); 3. This servlet is called by a jsp which is called from an Html file (by the tag: img src=myJsp.jsp) 4. When running only the servlet I can see the GIF file. 5. When I run the jsp I get the following error: Error 500: OutputStream is already being used for this request at org.apache.tomcat.core.ResponseImpl.getWriter(ResponseImpl.java:210) 6. running the html file fails 7. I can not use PrintWriter servlet because I need to pass binary data and not test. Thanks Tali Email: [EMAIL PROTECTED]
RE: [ERROR] OutputStream is already being used for this request
Yeah, you will have to also make sure to set the content-type to image/GIF in your %@ page ...% tag (I forget exact syntax right now). Otherwise, there will be a problem when content-type headers are sent twice: once from the JSP page, and then again from the servlet. -Mark [EMAIL PROTECTED] On Wed, 2 May 2001, CPC Livelink Admin wrote: Why do you need to use a JSP - The JSP is designed to product HTML output, and as such will always grab the writer and set the content type to text/html. What is wrong with just using the servlet, perhaps with an extention mapping . . . -Original Message- From: Tali Ambar [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 02, 2001 2:12 AM To: '[EMAIL PROTECTED]' Subject: FW: [ERROR] OutputStream is already being used for this request Hi 1. I'm trying to pass a stream to an html in order to see GIF files in a stream form on the browser. 2. I wrote (in a servlet) the following lines IStream stream = ...; // stream of a file in a GIF format response.setContentType (image/GIF); ServletOutputStream outStream = response.getOutputStream(); int p1 = 1; int[] p2 = new int[1]; byte bytes[] = new byte[1]; stream.RemoteRead(bytes,p1,p2); outStream.write(bytes); 3. This servlet is called by a jsp which is called from an Html file (by the tag: img src=myJsp.jsp) 4. When running only the servlet I can see the GIF file. 5. When I run the jsp I get the following error: Error 500: OutputStream is already being used for this request at org.apache.tomcat.core.ResponseImpl.getWriter(ResponseImpl.java:210) 6. running the html file fails 7. I can not use PrintWriter servlet because I need to pass binary data and not test. Thanks Tali Email: [EMAIL PROTECTED]
RE: [ERROR] OutputStream is already being used for this request
I agree, it's much safer to do this in a servlet. If someone accidentially adds whitespace to your JSP it can break! I have an example of this (using Struts) if it helps... -Original Message- From: CPC Livelink Admin [mailto:[EMAIL PROTECTED]] Sent: Wednesday, 2 May 2001 15:36 To: [EMAIL PROTECTED] Subject: RE: [ERROR] OutputStream is already being used for this request Why do you need to use a JSP - The JSP is designed to product HTML output, and as such will always grab the writer and set the content type to text/html. What is wrong with just using the servlet, perhaps with an extention mapping . . .