(JSP Problem) RequestDispatcher doesn't include output in place

Discussions

Web tier: servlets, JSP, Web frameworks: (JSP Problem) RequestDispatcher doesn't include output in place

  1. I don't know if this is a Tomcat problem or not. For some reason, when I try to include the output from another JSP using RequestDispatcher object, the output doesn't fall into correct place.

    The keyword "-Between-" should be rendered between "A" and "B" inside the table cell tag, but it was rendered all the way to the top of the HTML output. The same codes work fine under WebLogic 5.1(SP9) or above. The following is the
    sample codes to generate this problem:

    ----- [x.jsp] -----

    <TABLE>
      <TR>
        <TD>
        A
        <%
          RequestDispatcher rd = request.getRequestDispatcher("/y.jsp");
          rd.include(request, response);
        %>
        B
        </TD>
      </TR>
    </TABLE>

    ----- [y.jsp] -----

    -Between-

    ----- [HTML source from browser after x.jsp has been accessed] -----

    -Between-
    <TABLE>
    <TR>
    <TD>
    A

    B
    </TD>
    </TR>
    </TABLE>
  2. i don't understand your meaning exactly,if you want to link to other page by using RequestDipatcher?i use tomcat4,in my javabean,i use RequestDispatcher,it works well,but i use "rd.forward(request,response)"
  3. I was trying to include (or embed) the output of second JSP in the first JSP. That's why I am not using forward.

    The problem is, the output is being included in the wrong place.

    I wanted the output to be rendered in between the table cell tags, but instead, it was rendered at the beginning of the first JSP.

    I am using Tomcat4.01, JDK1.3, and solaris. The codes work perfectly fine under WebLogic. I also found out this does not work under OrionServer either. Strange!

    If anyone have tried this before, please let me know. Thanks!!
  4. try following code,

    <jsp:include page=filename/>
  5. If you want to use the request dispatcher, you will need to do an <% out.flush(); %> prior to making the call. But as the previous post indicates, you can use the <jsp:include page="" /> directive, which automatically does the flush.