servlet requestdispatching to another servlet (in iplanet plzzz)

Discussions

Web tier: servlets, JSP, Web frameworks: servlet requestdispatching to another servlet (in iplanet plzzz)

  1. hi,
       Please consider this scenario. I have written two projects in Proj1 and Proj2
    Proj1 has a servlet called servlet1
    Proj2 has a servlet called servlet2
    In servlet1 i want to dispatch request (forward) to servlet2
    getServletContext().getRequestDispatcher("Proj2/servlet2").forward(request,response);

    But the code does not forward request in iplanet. It gives an error like this

    error: SERVLET-fileext_not_set: Extension of file not found, while displaying static content

    the same code works fine in Netscape Application Server.
    i tried to forward request from one servlet1 to servlet3 in the same project in iplanet like this
    getServletContext().getRequestDispatcher("/servlet3").forward(request,response) it worked fine but the control came back to servlet1. why is it so. The servlets contain only system.out.println statements.

    can any one please tell me what to do.
    thanx in advance
    prithvim
  2. I'm not familiar with either environments, but it looks like the call to getRequestDispatcher("Proj2/servlet2") isn't finding "Proj2/servlet2". If Proj1 and Proj2 are deployed in separate web applications, you probably won't be able to forward requests between them. This might be what's happening. If you use an older Servlet engine (pre servlet 2.2), then you shouldn't encounter this problem, because the concept of web applications was introduced in servlet 2.2.

    My guess is that your version of iPlanet's servlet engine is 2.2 compliant, and you have Proj1 and Proj2 deployed in separate web applications. Also, your version of Netscape Application Server's servlet engine is probably not servlet 2.2 compliant, which is why your example works fine. If so, then the call to getRequestDispatcher("Proj2/servlet2") is looking for a file called servlet2 under the Proj2 directory under your Proj1 root directory. Some servlet engines will allow you to make ServletContexts shareable so that you can forward requests between web applications, but you'll have to read up on iPlanet to see if it supports this. If you can enable this option, you call servlets in other contexts like this:

    getServletContext().getContext("/Proj2").getRequestDispatcher("/servlet2").foward(request,response);
    return;

    The call to forward(request,response) invokes another another servlet, but processing continues in the forwarding servlet. It's just that the forwarding servlet shouldn't be able to send responses back to the user. It can still interact with the server system. Usually, you follow a call to forward(...) with return;.

    getServletContext().getRequestDispatcher("/servlet3").forward(request,response);
    return;

    Andy
  3. hi Andy Nguyen,
    Thanx a lot for that advice of u rs. u r idea of getContext the project directory and then dispatching worked.

    prithvi
  4. Your response here was greatly appreciated. It solved several problems that I have been dealing with.

    Thanks again.

    Bob