You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by George Finklang <ge...@gmail.com> on 2005/06/28 23:24:41 UTC

jsp include/RequestDispatcher incompatible?

have the following code in my jsp, which is called by a forward from my
Controller servlet. The various Dispatchers are either servlets or jsps declared
in my web.xml.

All the servlets and jsps get run correctly. The problem is the output. The
output of the root jsp and the 3-4 included jsps are arbitrarily rearranged, see
below. Bizarre shuffling, not reverse order, but a different order and not
interleaved with the text from the jsp. 

If I translate the jsp into servlet code, and use RequestDispatchers
for all the components,
the page works.  The documentation says something about flushing buffers, but I
can't see how to do this with RequestDispatchers.


Code:

<BODY>
<jsp:include page="WEB-INF/jsps/portal/header.jsp" flush="true"/>
<% if(option1) {
    application.getNamedDispatcher("Option1Servlet").include(request,response);
    } else { %>
<table><tr>
<% if(option2) { %>
<td><% 
      
application.getNamedDispatcher("Option2Servlet").include(request,response);
%></td>
<%  } %>
<td><% 
       application.getNamedDispatcher(page).include(request,response); %></td>
<td><% 
       application.getNamedDispatcher("InfoServlet").include(request,response);
%></td>
</tr></table>
<%  } %>
</BODY>



generated html:

<BODY>
 
 
Page text          // from the page dispatcher
 
Info servlet text   // from the infoservlet dispatcher
 
Header form text // from the header.jsp dispatcher
 
 
<table><tr>
 
<td></td>
<td></td>
</tr></table>
 
</BODY>

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


Re: jsp include/RequestDispatcher incompatible?

Posted by George Finklang <ge...@gmail.com>.
Feh.  Easier to just translate the whole jsp into a servlet by hand
which is what I already did.

--George

On 6/29/05, Tim Funk <fu...@joedog.org> wrote:
> Try flush first, otherwise you might need to pass a
> HttpServletResponseWrapper() to include() where the wrapper oversrides
> getOutputStream() (or getWriter()
> 
> -Tim
> 
> George Finklang wrote:
> > So before each request dispatcher call I need to call a flush on the
> > out in the JspPage?  How do I get access to it?
> >
> > Do I also need to call flush at the end of each request dispatcher call?
> >
> > --George
> >
> > On 6/28/05, Tim Funk <fu...@joedog.org> wrote:
> >
> >>The out from the jspwriter is NOT the same out as receieved by
> >>response.getWriter();
> >>
> >>The out in the JspPage is  buffered.
> >>
> >>-Tim
> >>
> >>George Finklang wrote:
> >>
> >>
> >>>have the following code in my jsp, which is called by a forward from my
> >>>Controller servlet. The various Dispatchers are either servlets or jsps declared
> >>>in my web.xml.
> >>>
> >>>All the servlets and jsps get run correctly. The problem is the output. The
> >>>output of the root jsp and the 3-4 included jsps are arbitrarily rearranged, see
> >>>below. Bizarre shuffling, not reverse order, but a different order and not
> >>>interleaved with the text from the jsp.
> >>>
> >>>If I translate the jsp into servlet code, and use RequestDispatchers
> >>>for all the components,
> >>>the page works.  The documentation says something about flushing buffers, but I
> >>>can't see how to do this with RequestDispatchers.
> >>>
> >>>
> >>>Code:
> >>>
> >>><BODY>
> >>><jsp:include page="WEB-INF/jsps/portal/header.jsp" flush="true"/>
> >>><% if(option1) {
> >>>    application.getNamedDispatcher("Option1Servlet").include(request,response);
> >>>    } else { %>
> >>><table><tr>
> >>><% if(option2) { %>
> >>><td><%
> >>>
> >>>application.getNamedDispatcher("Option2Servlet").include(request,response);
> >>>%></td>
> >>><%  } %>
> >>><td><%
> >>>       application.getNamedDispatcher(page).include(request,response); %></td>
> >>><td><%
> >>>       application.getNamedDispatcher("InfoServlet").include(request,response);
> >>>%></td>
> >>></tr></table>
> >>><%  } %>
> >>></BODY>
> >>>
> >>>
> >>>
> >>>generated html:
> >>>
> >>><BODY>
> >>>
> >>>
> >>>Page text          // from the page dispatcher
> >>>
> >>>Info servlet text   // from the infoservlet dispatcher
> >>>
> >>>Header form text // from the header.jsp dispatcher
> >>>
> >>>
> >>><table><tr>
> >>>
> >>><td></td>
> >>><td></td>
> >>></tr></table>
> >>>
> >>></BODY>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >>>
> >>>
> >>>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
>

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


Re: jsp include/RequestDispatcher incompatible?

Posted by Tim Funk <fu...@joedog.org>.
Try flush first, otherwise you might need to pass a 
HttpServletResponseWrapper() to include() where the wrapper oversrides 
getOutputStream() (or getWriter()

-Tim

George Finklang wrote:
> So before each request dispatcher call I need to call a flush on the
> out in the JspPage?  How do I get access to it?
> 
> Do I also need to call flush at the end of each request dispatcher call?
> 
> --George
> 
> On 6/28/05, Tim Funk <fu...@joedog.org> wrote:
> 
>>The out from the jspwriter is NOT the same out as receieved by
>>response.getWriter();
>>
>>The out in the JspPage is  buffered.
>>
>>-Tim
>>
>>George Finklang wrote:
>>
>>
>>>have the following code in my jsp, which is called by a forward from my
>>>Controller servlet. The various Dispatchers are either servlets or jsps declared
>>>in my web.xml.
>>>
>>>All the servlets and jsps get run correctly. The problem is the output. The
>>>output of the root jsp and the 3-4 included jsps are arbitrarily rearranged, see
>>>below. Bizarre shuffling, not reverse order, but a different order and not
>>>interleaved with the text from the jsp.
>>>
>>>If I translate the jsp into servlet code, and use RequestDispatchers
>>>for all the components,
>>>the page works.  The documentation says something about flushing buffers, but I
>>>can't see how to do this with RequestDispatchers.
>>>
>>>
>>>Code:
>>>
>>><BODY>
>>><jsp:include page="WEB-INF/jsps/portal/header.jsp" flush="true"/>
>>><% if(option1) {
>>>    application.getNamedDispatcher("Option1Servlet").include(request,response);
>>>    } else { %>
>>><table><tr>
>>><% if(option2) { %>
>>><td><%
>>>
>>>application.getNamedDispatcher("Option2Servlet").include(request,response);
>>>%></td>
>>><%  } %>
>>><td><%
>>>       application.getNamedDispatcher(page).include(request,response); %></td>
>>><td><%
>>>       application.getNamedDispatcher("InfoServlet").include(request,response);
>>>%></td>
>>></tr></table>
>>><%  } %>
>>></BODY>
>>>
>>>
>>>
>>>generated html:
>>>
>>><BODY>
>>>
>>>
>>>Page text          // from the page dispatcher
>>>
>>>Info servlet text   // from the infoservlet dispatcher
>>>
>>>Header form text // from the header.jsp dispatcher
>>>
>>>
>>><table><tr>
>>>
>>><td></td>
>>><td></td>
>>></tr></table>
>>>
>>></BODY>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 

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


Re: jsp include/RequestDispatcher incompatible?

Posted by George Finklang <ge...@gmail.com>.
So before each request dispatcher call I need to call a flush on the
out in the JspPage?  How do I get access to it?

Do I also need to call flush at the end of each request dispatcher call?

--George

On 6/28/05, Tim Funk <fu...@joedog.org> wrote:
> The out from the jspwriter is NOT the same out as receieved by
> response.getWriter();
> 
> The out in the JspPage is  buffered.
> 
> -Tim
> 
> George Finklang wrote:
> 
> > have the following code in my jsp, which is called by a forward from my
> > Controller servlet. The various Dispatchers are either servlets or jsps declared
> > in my web.xml.
> >
> > All the servlets and jsps get run correctly. The problem is the output. The
> > output of the root jsp and the 3-4 included jsps are arbitrarily rearranged, see
> > below. Bizarre shuffling, not reverse order, but a different order and not
> > interleaved with the text from the jsp.
> >
> > If I translate the jsp into servlet code, and use RequestDispatchers
> > for all the components,
> > the page works.  The documentation says something about flushing buffers, but I
> > can't see how to do this with RequestDispatchers.
> >
> >
> > Code:
> >
> > <BODY>
> > <jsp:include page="WEB-INF/jsps/portal/header.jsp" flush="true"/>
> > <% if(option1) {
> >     application.getNamedDispatcher("Option1Servlet").include(request,response);
> >     } else { %>
> > <table><tr>
> > <% if(option2) { %>
> > <td><%
> >
> > application.getNamedDispatcher("Option2Servlet").include(request,response);
> > %></td>
> > <%  } %>
> > <td><%
> >        application.getNamedDispatcher(page).include(request,response); %></td>
> > <td><%
> >        application.getNamedDispatcher("InfoServlet").include(request,response);
> > %></td>
> > </tr></table>
> > <%  } %>
> > </BODY>
> >
> >
> >
> > generated html:
> >
> > <BODY>
> >
> >
> > Page text          // from the page dispatcher
> >
> > Info servlet text   // from the infoservlet dispatcher
> >
> > Header form text // from the header.jsp dispatcher
> >
> >
> > <table><tr>
> >
> > <td></td>
> > <td></td>
> > </tr></table>
> >
> > </BODY>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
>

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


Re: jsp include/RequestDispatcher incompatible?

Posted by Tim Funk <fu...@joedog.org>.
The out from the jspwriter is NOT the same out as receieved by 
response.getWriter();

The out in the JspPage is  buffered.

-Tim

George Finklang wrote:

> have the following code in my jsp, which is called by a forward from my
> Controller servlet. The various Dispatchers are either servlets or jsps declared
> in my web.xml.
> 
> All the servlets and jsps get run correctly. The problem is the output. The
> output of the root jsp and the 3-4 included jsps are arbitrarily rearranged, see
> below. Bizarre shuffling, not reverse order, but a different order and not
> interleaved with the text from the jsp. 
> 
> If I translate the jsp into servlet code, and use RequestDispatchers
> for all the components,
> the page works.  The documentation says something about flushing buffers, but I
> can't see how to do this with RequestDispatchers.
> 
> 
> Code:
> 
> <BODY>
> <jsp:include page="WEB-INF/jsps/portal/header.jsp" flush="true"/>
> <% if(option1) {
>     application.getNamedDispatcher("Option1Servlet").include(request,response);
>     } else { %>
> <table><tr>
> <% if(option2) { %>
> <td><% 
>       
> application.getNamedDispatcher("Option2Servlet").include(request,response);
> %></td>
> <%  } %>
> <td><% 
>        application.getNamedDispatcher(page).include(request,response); %></td>
> <td><% 
>        application.getNamedDispatcher("InfoServlet").include(request,response);
> %></td>
> </tr></table>
> <%  } %>
> </BODY>
> 
> 
> 
> generated html:
> 
> <BODY>
>  
>  
> Page text          // from the page dispatcher
>  
> Info servlet text   // from the infoservlet dispatcher
>  
> Header form text // from the header.jsp dispatcher
>  
>  
> <table><tr>
>  
> <td></td>
> <td></td>
> </tr></table>
>  
> </BODY>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 

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