You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by da...@oracle.com on 2000/07/06 23:10:29 UTC

Problem using RequestDispatcher.forward()

I've got a servlet which uses the RequestDispatcher.forward method, or
should I say, tries to use the method.  The problem is that the
RequestDispatcher seems to being created, but the attempt to forward
returns a http 404 error (file not found) rather than the file itself.
However, if I just type in the file path I'm using to create the
RequestDispatcher directly into my browser's Address, it comes up just
fine.

Any ideas on what's wrong, or is forward() not implemented correctly in
Tomcat?  I tried the same code using the Orion web server and it worked
fine.

Thanks,

David

Here's my simple test case code:

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;

 public class ForwardServlet extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    {
      String path = "/test/forward.html";
      RequestDispatcher rd = req.getRequestDispatcher(path);
      System.out.println("path="+path);
      if (rd != null)
      {
        System.out.println("rd is not null!");
        System.out.println("rd toString="+rd);
      }
      else
      {
        System.out.println("rd is null!");
      }
      System.out.println("forwarding request");
      rd.forward(req, res);
    }

}