tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry Isaacs <Larry.Isa...@sas.com>
Subject RE: Problem using RequestDispatcher.forward()
Date Fri, 07 Jul 2000 14:23:23 GMT
In case you haven't already discovered this, your example as a web application assumes the
following directory structure:

<mywebapp>/test/forward.html
<mywebapp>/WEB-INF/classes/ForwardServet.java

If instead, these files are part of a "/test" web application, your directory structure would
be:

test/forward.html
test/WEB-INF/classes/ForwardServlet.java

If this is actually your case, then the path should be "/forward.html" instead of "/test/forward.html".
 Per the Servlet 2.2 spec, paths that begin with "/" are relative to the web application base
directory.

Hope this helps.

Larry
	

-----Original Message-----
From: david.lane@oracle.com [mailto:david.lane@oracle.com]
Sent: Thursday, July 06, 2000 5:10 PM
To: tomcat-user@jakarta.apache.org
Subject: 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);
    }

}


Mime
View raw message