tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karl Goldstein" <>
Subject Re: JSP implicit writer (out) vs. response.getWriter()
Date Mon, 24 Nov 2003 03:33:18 GMT
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) {
      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);



Karl Goldstein
  ----- Original Message ----- 
  From: Karl Goldstein 
  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:

  Me first.
  <% response.getWriter().println("Me second"); %>

  I was surprised to discover that the out of this is:

  Me second.
  Me first.

  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().


  Karl Goldstein
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message