"Steve McCarthy" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> Steve, >> >> In 8916 - if you use: >> >> service() { >> w= new PrintWriter( response.getOutputStream ); >> w.println(...) >> } >> >> If you don't flush, then you'll get no output. >> >> That's not because of the servlet spec - but because of the way >> PrintWriter works, it'll put your output in a buffer and that'll not be >> written to the output stream. >> > Please note that the example uses a PrintWriter, and not a > BufferedWriter. Looking at the source of PrintWriter, all of the > println() methods write the data to the underlying OutputStream - > characters are not buffered Writer level. If there is any buffering, it > occurs in the OutputStream provided by the container, and is therefore > available to the container. > > It isn't any different than obtaining the OutputStream from the > container, writing bytes to it, and then not calling flush on the > OutputStream: > > service(...) { > OutputStream os = response.getOutputStream(); > byte arr[] = ".......".getBytes(); > os.write(arr); > // no os.flush(); > }
Hmm... That actually (I tried it) works on 4.0.3 with the HTTP connector (I have my doubts about Coyote, it simply crashes with an NPE)... Look: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Steve extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { OutputStream os = res.getOutputStream(); byte arr[] = ".......".getBytes(); os.write(arr); } } [pier@blossom] ~ $ telnet localhost 8080 Trying 127.0.0.1... Connected to localhost.betaversion.org. Escape character is '^]'. GET /servlet/Steve HTTP/1.1 Host: localhost:8080 Connection: close HTTP/1.1 200 OK Date: Fri, 10 May 2002 00:19:12 GMT Server: Apache Tomcat/4.0.3 (HTTP/1.1 Connector) Connection: close .......Connection closed by foreign host. [pier@blossom] ~ $ The problem _I_ had with AvantGo is the following: Given this _very_ stupid but _very_ valid servlet: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Test extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setStatus(302); res.setContentLength(0); res.setHeader("Location","http://www.vnunet.com/PDARedirected"); } } Check out what the _hell_ does happen... (I'm doing it with keep alive so you'll get the extent of the damage): [pier@blossom] ~ $ telnet localhost 8080 Trying 127.0.0.1... Connected to localhost.betaversion.org. Escape character is '^]'. GET /servlet/Test HTTP/1.1 Host: localhost:8080 HTTP/1.1 302 Moved Temporarily Content-Type: text/html Content-Length: 0 Date: Fri, 10 May 2002 00:25:16 GMT Location: http://www.vnunet.com/PDARedirected Server: Apache Tomcat/4.0.3 (HTTP/1.1 Connector) <html><head><title>Apache Tomcat/4.0.3 - Error report</title><STYLE><!--H1{font-family : sans-serif,Arial,Tahoma;color : white;background-color : #0086b2;} BODY{font-family : sans-serif,Arial,Tahoma;color : black;background-color : white;} B{color : white;background-color : #0086b2;} HR{color : #0086b2;} --></STYLE> </head><body><h1>Apache Tomcat/4.0.3 - HTTP Status 302 - Moved Temporarily</h1><HR size="1" noshade><p><b>type</b> Status report</p><p><b>message</b> <u>Moved Temporarily</u></p><p><b>description</b> <u>The requested resource (Moved Temporarily) has moved temporarily to a new location.</u></p><HR size="1" noshade></body></html>GET /servlet/Test HTTP/1.1 Host: localhost:8080 HTTP/1.1 302 Moved Temporarily Content-Type: text/html Content-Length: 0 Date: Fri, 10 May 2002 00:25:24 GMT Location: http://www.vnunet.com/PDARedirected Server: Apache Tomcat/4.0.3 (HTTP/1.1 Connector) <html><head><title>Apache Tomcat/4.0.3 - Error report</title><STYLE><!--H1{font-family : sans-serif,Arial,Tahoma;color : white;background-color : #0086b2;} BODY{font-family : sans-serif,Arial,Tahoma;color : black;background-color : white;} B{color : white;background-color : #0086b2;} HR{color : #0086b2;} --></STYLE> </head><body><h1>Apache Tomcat/4.0.3 - HTTP Status 302 - Moved Temporarily</h1><HR size="1" noshade><p><b>type</b> Status report</p><p><b>message</b> <u>Moved Temporarily</u></p><p><b>description</b> <u>The requested resource (Moved Temporarily) has moved temporarily to a new location.</u></p><HR size="1" noshade></body></html>^] telnet> close Connection closed. [pier@blossom] ~ $ My servlet _says_ it's a 302, temporary redirect, my servlet _says_ the content length is 0, my servlet doesn't touch even barely the stupid stream because it got nothing to do with the sucker, and then, I still get back some text, _AND_ the Content-Length saying that there MUST NOT BE... This _screws_ up all my requests... Allloooffftthhheemmmm... Keep alive is dropped, and mess mess mess on all PDAs... ARRRRGGGGHHHH I hate the ErrorReporterCrap... Pier -- I think that it's extremely foolish to name a server after the current U.S. President. B.W. Fitzpatrick -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>