You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Leong Mun Wai <mu...@cyberway.com.sg> on 2001/04/16 05:29:40 UTC
[Tomcat 4 b3] Problem with request forwarding in a servlet
Hi,
There seems to be a problem with RequestDispatcher.forward() when used in a
Servlet. On the first load, the Servlet returnes a blank page. Forwarding to
a non-existent page does not return null either. On the second load, all
hell breaks loose and the Servlet goes into an infinite loop, finally ending
with a StackOverflow exception. The method works fine in a JSP though.
Here's my test code:
package demo.testing;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class FwdTestServlet extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
String fwdPage = req.getParameter("page");
RequestDispatcher rd = req.getRequestDispatcher(fwdPage);
if (rd == null) {
throw new ServletException("Page " + fwdPage + " not found");
}
System.out.println("Forwarding to " + fwdPage);
rd.forward(req, res);
}
}
Thanks!
Mun Wai