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

Bug re: implementation of RequestDispatcher.forward()

I'm using tomcat 3.1 on Windows NT and seem to have found a bug in the
implementation of the forward method of the RequestDispatcher object.

In my simple case below the problem is that the RequestDispatcher is
created successfully (rd is not null), but the attempt to forward
returns a http 404 error (file not found) rather than the file itself.
I've tested that the file can be found by just typing in the same file
path used to create the RequestDispatcher directly into the browser's
address field (the html file is found, no problem).  I've also tested
the same code using Orion and it works fine there.

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!");
      }
      else
      {
        System.out.println("rd is null!");
      }
      System.out.println("forwarding request");
      rd.forward(req, res);
    }

}

My file system looks like:
tomcat
   webapps
        test
           forward.html (just a simple html file, any file will do)

I've verified that tomcat can find the file by typing:
http://my_machine/test/forward.html
into the address field and the file is displayed, so I know tomcat can
find the file.

Re: Bug re: implementation of RequestDispatcher.forward()

Posted by Hans Bergsten <ha...@gefionsoftware.com>.
david.lane@oracle.com wrote:
> 
> I'm using tomcat 3.1 on Windows NT and seem to have found a bug in the
> implementation of the forward method of the RequestDispatcher object.
> 
> In my simple case below the problem is that the RequestDispatcher is
> created successfully (rd is not null), but the attempt to forward
> returns a http 404 error (file not found) rather than the file itself.
> I've tested that the file can be found by just typing in the same file
> path used to create the RequestDispatcher directly into the browser's
> address field (the html file is found, no problem).  I've also tested
> the same code using Orion and it works fine there.
> 
> 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!");
>       }
>       else
>       {
>         System.out.println("rd is null!");
>       }
>       System.out.println("forwarding request");
>       rd.forward(req, res);
>     }
> 
> }
> 
> My file system looks like:
> tomcat
>    webapps
>         test
>            forward.html (just a simple html file, any file will do)
> 
> I've verified that tomcat can find the file by typing:
> http://my_machine/test/forward.html
> into the address field and the file is displayed, so I know tomcat can
> find the file.

The URI path you use with getRD() must be context relative. In other words,
must not contain the URI path prefix that is associated with your servlet
context (web application). In your case, since you have the page in 
webapps/test, your application's URI path prefix is /test. You should then
call getRD() with the path /forward.html.

Hans
-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com