tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 21440] - <jsp:include> whose target performs a 'forward' does not behave as expected
Date Wed, 09 Jul 2003 22:40:18 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21440>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21440

<jsp:include> whose target performs a 'forward' does not behave as expected





------- Additional Comments From jan.luehe@sun.com  2003-07-09 22:40 -------
I believe I have a fix for testcase_1:

<jsp:include> wraps the response into an instance of
org.apache.jasper.runtime..ServletResponseWrapperInclude, so that the
included resource may append its output to the output buffer of the
including page.

Therefore, in the case of "ForwardServlet", the response object passed
to RequestDispatcher.forward() is an instance of
ServletResponseWrapperInclude. RequestDispatcher.forward() calls
resetBuffer() on the response object, which
ServletResponseWrapperInclude delegates to the wrapped response. At
this point, "***1***" has not been committed to the response buffer
yet: it was buffered in the JspWriter associated with the including
page, to which the PrintWriter associated with the
ServletResponseWrapperInclude appends. This means that calling
resetBuffer() on the response does not really have any effect, and
therefore, "FOO" gets appended to "***1***".

On the other hand, when replacing "ForwardServlet" with "forward.jsp",
the code generated for "forward.jsp" calls RequestDispatcher.forward()
with a response object obtained as follows:

  // Make sure that the response object is not the wrapper for include
  while (response instanceof ServletResponseWrapperInclude) {
    response = ((ServletResponseWrapperInclude)response).getResponse();
  }

As a consequence of passing the original response to the
RequestDispatcher, the response consists of just "FOO", which does not
get appended to "***1***".

A fix is to override ServletResponseWrapperInclude.resetBuffer() as follows:

    public void resetBuffer() {
	try {
	    writer.clearBuffer();
	} catch (IOException ioe) {
	}
    }

which clears the output buffer of the including page, which is what we want.

However, independently of this fix, running testcase_1 throws this exception:

  SEVERE: Servlet.service() for servlet jsp threw exception
  java.io.IOException: Stream closed
        at
org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:233)
        at
org.apache.jasper.runtime.JspWriterImpl.clearBuffer(JspWriterImpl.java:188)
        at org.apache.jsp.test1_jsp._jspService(test1_jsp.java:48)

When replacing "ForwardServlet" with "forward.jsp", it throws this exception:

  SEVERE: Servlet.service() for servlet jsp threw exception
  java.lang.IllegalStateException: getOutputStream() has already been called for
this response
        at
org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:628)
        at
org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:192)
        at
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:165)
        at
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:158)
        at
org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:245)
        at
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:160)
        at
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:120)
        at org.apache.jsp.test11_jsp._jspService(test11_jsp.java:52)


Still investigating ....


Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message