You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "j.random.programmer" <ja...@yahoo.com> on 2006/07/01 00:33:31 UTC

Critical bug in RequestDispatcher.include(..) in Tomcat 5.5.16 ?

Is this my imagination or is tomcat really this
retarded and this insanely buggy ? Or am I 
doing something wrong ?

----------------- x.jsp --------------------------
foo

<%
RequestDispatcher rd =
request.getRequestDispatcher("/foo.html");
rd.include(request, response);
%>

test;
-----------------end---------------------------------

------------- start foo.html ------------------------
This is a foo page, with some dummy html
-------------------------------------------------

Now, when i try to get "x.jsp", I get:

HTTP Status 500 -

type Exception report
message
description The server encountered an internal error
() that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: getOutputStream()
has already been called for this response

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause
java.lang.IllegalStateException: getOutputStream() has
already been called for this response

org.apache.catalina.connector.Response.getWriter(Response.java:599)

org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)

org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)

org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)

org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)

org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)

org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
	org.apache.jsp.vbb.x_jsp._jspService(x_jsp.java:56)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is
available in the Apache Tomcat/5.5.16 logs.

Apache Tomcat/5.5.16

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Critical bug in RequestDispatcher.include(..) in Tomcat 5.5.16 ?

Posted by Tim Funk <fu...@joedog.org>.
You need to be using
<jsp:include page="/foo.html" />

Under the covers getOutputStream during the include. But a getWriter was 
already called. Once you call getWriter - you can't call getOutputStream, or 
you get the ISE.

jsp:include gets aroung this by wrapping the response and wrapping 
getOutputStream to avoid this issue.

-Tim

j.random.programmer wrote:
> Is this my imagination or is tomcat really this
> retarded and this insanely buggy ? Or am I 
> doing something wrong ?
> 
> ----------------- x.jsp --------------------------
> foo
> 
> <%
> RequestDispatcher rd =
> request.getRequestDispatcher("/foo.html");
> rd.include(request, response);
> %>
> 
> test;
> -----------------end---------------------------------
> 
> ------------- start foo.html ------------------------
> This is a foo page, with some dummy html
> -------------------------------------------------
> 
> Now, when i try to get "x.jsp", I get:
> 
> HTTP Status 500 -
> 
> type Exception report
> message
> description The server encountered an internal error
> () that prevented it from fulfilling this request.
> exception
> org.apache.jasper.JasperException: getOutputStream()
> has already been called for this response
> 
> org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
> 
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
> 
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
> 
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
> 
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> 
> root cause
> java.lang.IllegalStateException: getOutputStream() has
> already been called for this response
> 
> org.apache.catalina.connector.Response.getWriter(Response.java:599)
> 
> org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)
> 
> org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)
> 
> org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)
> 
> org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)
> 
> org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
> 
> org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
> 	org.apache.jsp.vbb.x_jsp._jspService(x_jsp.java:56)
> 
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
> 
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> 
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
> 
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
> 
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
> 
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> 
> note The full stack trace of the root cause is
> available in the Apache Tomcat/5.5.16 logs.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Critical bug in RequestDispatcher.include(..) in Tomcat 5.5.16 ?

Posted by Garth Patil <ga...@gmail.com>.
Sorry. I don't think I read your initial post closely enough the first
time. It appears that the DefalutServlet (when called in this fashion)
that is serving the static html resource is closing the output stream.
The Servlet specification seems to indicate that attempts to do that
should be ignored by the implementation:
"The include method of the RequestDispatcher interface may be called
at any time.
The target servlet of the include method has access to all aspects of
the request
object, but its use of the response object is more limited.
    It can only write information to the ServletOutputStream or Writer of the
response object and commit a response by writing content past the end of the
response buffer, or by explicitly calling the flushBuffer method of the
ServletResponse interface. It cannot set headers or call any method that affects
the headers of the response. Any attempt to do so must be ignored."

Given that this seems to be a Tomcat implementation problem, perhaps
this should be brought up on the tomcat-dev list. In the meantime,
users should use @include or jsp:include if they want to do this in a
jsp.
<%@ include file="/foo.html" %>
<jsp:include page="/foo.html" />

Best,
Garth

On 7/1/06, j.random.programmer <ja...@yahoo.com> wrote:
> > I didn't see him mention "forward", you do
> > understand what he's saying
> > right?
> >
>
> No I don't. Which is why this looks like a fairly
> serious bug from
> where I am standing. You may want to read the
> specification about
> what an "include" is and how it differs from
> "forward".
>
> The spec. explicity states that "forwards" close the
> output stream before
> returning but "includes" DO NOT and that the include
> method of the
> request dispatcher may be called anytime (and as many
> times).
>
> You do understand that part of the spec ?
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Critical bug in RequestDispatcher.include(..) in Tomcat 5.5.16 ?

Posted by "j.random.programmer" <ja...@yahoo.com>.
> I didn't see him mention "forward", you do
> understand what he's saying
> right?
> 

No I don't. Which is why this looks like a fairly
serious bug from
where I am standing. You may want to read the
specification about
what an "include" is and how it differs from
"forward".

The spec. explicity states that "forwards" close the
output stream before
returning but "includes" DO NOT and that the include
method of the
request dispatcher may be called anytime (and as many
times).

You do understand that part of the spec ?

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Critical bug in RequestDispatcher.include(..) in Tomcat 5.5.16 ?

Posted by Pid <p...@pidster.com>.
I didn't see him mention "forward", you do understand what he's saying
right?



j.random.programmer wrote:
> You do understand that we are talking about an
> include, not a 
> forward right ? 
> 
> --- Garth Patil <ga...@gmail.com> wrote:
> 
>> Try using the same code in a servlet, and you won't
>> have a problem. If
>> you try this in a jsp and there is _any_ whitespace
>> after the last
>> "%>" the jsp renderer will try to reopen the output
>> stream (to render
>> the whitespace), which is already closed. That is
>> the error you are
>> seeing here. If you want to include other markup or
>> jsp's in your jsp
>> pages use the @include or jsp:include tags.
>> Best,
>> Garth
>>
>> On 6/30/06, j.random.programmer
>> <ja...@yahoo.com> wrote:
>>> Is this my imagination or is tomcat really this
>>> retarded and this insanely buggy ? Or am I
>>> doing something wrong ?
>>>
>>> ----------------- x.jsp --------------------------
>>> foo
>>>
>>> <%
>>> RequestDispatcher rd =
>>> request.getRequestDispatcher("/foo.html");
>>> rd.include(request, response);
>>> %>
>>>
>>> test;
>>>
> -----------------end---------------------------------
>>> ------------- start foo.html
>> ------------------------
>>> This is a foo page, with some dummy html
>>> -------------------------------------------------
>>>
>>> Now, when i try to get "x.jsp", I get:
>>>
>>> HTTP Status 500 -
>>>
>>> type Exception report
>>> message
>>> description The server encountered an internal
>> error
>>> () that prevented it from fulfilling this request.
>>> exception
>>> org.apache.jasper.JasperException:
>> getOutputStream()
>>> has already been called for this response
>>>
>>>
> org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
>>>
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
>>>
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
>>>
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
>>>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>> root cause
>>> java.lang.IllegalStateException: getOutputStream()
>> has
>>> already been called for this response
>>>
>>>
> org.apache.catalina.connector.Response.getWriter(Response.java:599)
>>>
> org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)
>>>
> org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)
>>>
> org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)
>>>
> org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)
>>>
> org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
>>>
> org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
>>>        
>> org.apache.jsp.vbb.x_jsp._jspService(x_jsp.java:56)
>>>
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
>>>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>>
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
>>>
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
>>>
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
>>>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>> note The full stack trace of the root cause is
>>> available in the Apache Tomcat/5.5.16 logs.
>>>
>>> Apache Tomcat/5.5.16
>>>
>>> __________________________________________________
>>> Do You Yahoo!?
>>> Tired of spam?  Yahoo! Mail has the best spam
>> protection around
>>> http://mail.yahoo.com
>>>
>>>
> ---------------------------------------------------------------------
>>> To start a new topic, e-mail:
>> users@tomcat.apache.org
>>> To unsubscribe, e-mail:
>> users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail:
>> users-help@tomcat.apache.org
>>>
>>
> ---------------------------------------------------------------------
>> To start a new topic, e-mail:
>> users@tomcat.apache.org
>> To unsubscribe, e-mail:
>> users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail:
>> users-help@tomcat.apache.org
>>
>>
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Critical bug in RequestDispatcher.include(..) in Tomcat 5.5.16 ?

Posted by "j.random.programmer" <ja...@yahoo.com>.
You do understand that we are talking about an
include, not a 
forward right ? 

--- Garth Patil <ga...@gmail.com> wrote:

> Try using the same code in a servlet, and you won't
> have a problem. If
> you try this in a jsp and there is _any_ whitespace
> after the last
> "%>" the jsp renderer will try to reopen the output
> stream (to render
> the whitespace), which is already closed. That is
> the error you are
> seeing here. If you want to include other markup or
> jsp's in your jsp
> pages use the @include or jsp:include tags.
> Best,
> Garth
> 
> On 6/30/06, j.random.programmer
> <ja...@yahoo.com> wrote:
> > Is this my imagination or is tomcat really this
> > retarded and this insanely buggy ? Or am I
> > doing something wrong ?
> >
> > ----------------- x.jsp --------------------------
> > foo
> >
> > <%
> > RequestDispatcher rd =
> > request.getRequestDispatcher("/foo.html");
> > rd.include(request, response);
> > %>
> >
> > test;
> >
>
-----------------end---------------------------------
> >
> > ------------- start foo.html
> ------------------------
> > This is a foo page, with some dummy html
> > -------------------------------------------------
> >
> > Now, when i try to get "x.jsp", I get:
> >
> > HTTP Status 500 -
> >
> > type Exception report
> > message
> > description The server encountered an internal
> error
> > () that prevented it from fulfilling this request.
> > exception
> > org.apache.jasper.JasperException:
> getOutputStream()
> > has already been called for this response
> >
> >
>
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
> >
> >
>
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
> >
> >
>
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
> >
> >
>
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
> >
> >
>
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> >
> > root cause
> > java.lang.IllegalStateException: getOutputStream()
> has
> > already been called for this response
> >
> >
>
org.apache.catalina.connector.Response.getWriter(Response.java:599)
> >
> >
>
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)
> >
> >
>
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)
> >
> >
>
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)
> >
> >
>
org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)
> >
> >
>
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
> >
> >
>
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
> >        
> org.apache.jsp.vbb.x_jsp._jspService(x_jsp.java:56)
> >
> >
>
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
> >
> >
>
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> >
> >
>
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
> >
> >
>
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
> >
> >
>
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
> >
> >
>
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> >
> > note The full stack trace of the root cause is
> > available in the Apache Tomcat/5.5.16 logs.
> >
> > Apache Tomcat/5.5.16
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To start a new topic, e-mail:
> users@tomcat.apache.org
> > To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail:
> users-help@tomcat.apache.org
> >
> >
> 
>
---------------------------------------------------------------------
> To start a new topic, e-mail:
> users@tomcat.apache.org
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Critical bug in RequestDispatcher.include(..) in Tomcat 5.5.16 ?

Posted by Garth Patil <ga...@gmail.com>.
Try using the same code in a servlet, and you won't have a problem. If
you try this in a jsp and there is _any_ whitespace after the last
"%>" the jsp renderer will try to reopen the output stream (to render
the whitespace), which is already closed. That is the error you are
seeing here. If you want to include other markup or jsp's in your jsp
pages use the @include or jsp:include tags.
Best,
Garth

On 6/30/06, j.random.programmer <ja...@yahoo.com> wrote:
> Is this my imagination or is tomcat really this
> retarded and this insanely buggy ? Or am I
> doing something wrong ?
>
> ----------------- x.jsp --------------------------
> foo
>
> <%
> RequestDispatcher rd =
> request.getRequestDispatcher("/foo.html");
> rd.include(request, response);
> %>
>
> test;
> -----------------end---------------------------------
>
> ------------- start foo.html ------------------------
> This is a foo page, with some dummy html
> -------------------------------------------------
>
> Now, when i try to get "x.jsp", I get:
>
> HTTP Status 500 -
>
> type Exception report
> message
> description The server encountered an internal error
> () that prevented it from fulfilling this request.
> exception
> org.apache.jasper.JasperException: getOutputStream()
> has already been called for this response
>
> org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
>
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
>
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
>
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>
> root cause
> java.lang.IllegalStateException: getOutputStream() has
> already been called for this response
>
> org.apache.catalina.connector.Response.getWriter(Response.java:599)
>
> org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)
>
> org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)
>
> org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)
>
> org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)
>
> org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
>
> org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
>         org.apache.jsp.vbb.x_jsp._jspService(x_jsp.java:56)
>
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
>
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
>
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>
> note The full stack trace of the root cause is
> available in the Apache Tomcat/5.5.16 logs.
>
> Apache Tomcat/5.5.16
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org