Hi again!
It seems like the problem is related to buffers since it resolved itself
when I added a out.flush() before calling the "sub-page".

I don't know if this qualify as a bug? It sure is annoying that data can
come out in a different order than the pagelayout would indicate.

Regards
Roland Carlsson

----- Original Message -----
From: "Roland Carlsson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, October 14, 2002 9:48 AM
Subject: RequestDispatcher


Hi!
I got a problem with the RequestDispatcher. I'm trying to make a simple
framwork to include jsp-pages as components into a template-jsp. But I
doesn't get the pages nested the way I'd like it. Could anyone please
explain why the RequestDispatcher puts page2 before page1 instead of inside
page1.

Thanks in advance
Roland Carlsson


Setup:
Apache 1.3.22
Tomcat 4
Windows Nt4 sp5

Example and source:

Imagine these two jsp-files.

-------------- page one---------------

test1
<%
Machine m = Machine.getInstance();
m.sub(request, response, 1);
%>
test1 end

------------- page two ------------

test2
test2 end

---------- resultpage -----------

test2
test2 end
test1
test1 end

-------- what I expeced --------

test1
test2
test2 end
test1 end

--------- Source of Machine.sub() -----------------

  public void sub(HttpServletRequest request, HttpServletResponse response,
int i){
    try{
    // Get a database connection
    // FixMe: get from a pool
    Class.forName("oracle.jdbc.driver.OracleDriver");
        StringBuffer sb = new StringBuffer();
        sb.append("jdbc:oracle:thin:");
        sb.append("xxxx");
        sb.append("/");
        sb.append("xxxx");
        sb.append("@xxxx:xxxx:xxxx:");
        sb.append("xxxx");
        Connection conn = DriverManager.getConnection(sb.toString());

      // Get a Component from the request
      Component oldComp = (Component) request.getAttribute("_komponent");
      // Get Children from the component
      java.util.ArrayList al=  oldComp.getChildren(conn);
      // Get the Component we want for this request
      Component newComp = (Component) oldComp.getChildren(conn).get(i);
      // Populate the child
      newComp.sql_select(conn);
      // Set the child into the request so it will be parent for
sub-components
      request.setAttribute("_komponent", newComp);
      // Include a sub-component into the page
      request.getRequestDispatcher(newComp.getUrl()).include(request,
response);
      // Restore state
      request.setAttribute("_komponent", oldComp);
      // Release db
      conn.close();
    }catch(Exception e){
      e.printStackTrace();
    }finally{

    }
  }


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to