Java Servlet Dispatcher: Issues with include()

Discussion in 'OT Technology' started by Astro, Jul 18, 2003.

  1. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    I've been attempting to create a functional dispatcher that I can use for any site I create from this point on. I found some code for a dispatcher from "Usering Java Server Pages and Servlets" (its a Que book) and their code always seems to be a bit sketchy.

    The problem I'm having is based from this code:

    Code:
    RequestDispatcher d = request.getRequestDispatcher("/myclass");
    if(d != null)
    {
    	// invoke the next controller
    	d.include(request, response);
    	PrintWriter out = response.getWriter();
    	out.println(request.getAttribute("username2"));
    }  // end if(d != null)
    
    So in theory, the "myclass" should get run and return control from "d.include(request, response)". It would also be clear that "myclass" will have access to the request and response data.

    Well, it doesn't error out (which I guess is good). It does make it into the if() (meaning d is not null), but I'm not getting any output from "myclass". I've got it set to print output, I've got it set to send email, raise errors, set attributes in the request object, and I'm not getting anything.

    So, when include() is run, I'm assuming the service() method of "myclass" will execute. Is this assumption wrong? Is there a way to make this work (or better yet, prove this works)

    Second issue is does the request object stay global during the include() call? As in, I pass the request object to "myclass". If "myclass" modifies the request object, will that same object be available once "myclass" is complete? Or do I need to resort to sessions to make this work?
     
  2. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
  3. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Progress in baby steps: I've got include at least executing a designated chunk of code (I ended up switching include() to forward() and Tomcat decided to clear the cache out. I switched it back to include() and nothing broke).

    Update: Yes, you can pass the request object, modify it, and maintain the changes back in the caller (if that makes sense). Whew! I'm pretty stoked now!
     
  4. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    hmmmm Tomcat.

    Wish i could help ya man, but my java guy is on vacation :squint:
     

Share This Page