After thinking about it a bit more, it seems the solution to the issue I raised yesterday is potentially simple: just use a "wrapped" response for the JSP response variable, which returns the JspWriter.
create a new package class JspResponseWrapper: class JspResponseWrapper extends HttpServletResponseWrapper { private Writer out; JspResponseWrapper(HttpServletResponse response, JspWriter out) { super(response); this.out = out; } public Writer getWriter() { return out; } ...override other methods related to output stream/writer } Then in PageContextImpl._initialize: this.response = new JspResponseWriter(response, this.out); Thoughts? Regards, Karl Goldstein ----- Original Message ----- From: Karl Goldstein To: [EMAIL PROTECTED] Sent: Saturday, November 22, 2003 10:32 PM Subject: JSP implicit writer (out) vs. response.getWriter() Hi all, I recently started working with Tomcat (4.1.29) and ran into an inconsistency between the implicit "out" variable in a JSP and response.getWriter(). Consider this JSP: <html> <body> Me first. <% response.getWriter().println("Me second"); %> </body> </html> I was surprised to discover that the out of this is: Me second. <html> <body> Me first. </body> </html> Looking at org.apache.jasper.runtime.PageContextImpl and JspWriterImpl, it appears that the "out" variable is set up with its own buffer, which explains why text sent straight to the response writer appears first (before the JSP writer buffer gets flushed). Am I missing something or is this the way it actually works? If I have it straight, is this a bug? I'm not sure about the JSP spec, but other app servers I've tried seem to accumulate text in a single buffer for both "out" and response.getWriter(). Thanks, Karl Goldstein