If I forward a request via a RequestDispatcher to another servlet, which method (doGet, doPost, etc) would end up called in the new servlet?
Another related scenario is if I use <%@ page errorPage="MyServlet" %> in my JSP which causes an exception and MyServlet is a Servlet (rather than JSP), which method of my MyServlet is called? I think neither doGet nor doPost is a logical choice because there is no Http client and the actual client is my JSP page throwing an exception!
Originally posted by Alec Lee: If I forward a request via a RequestDispatcher to another servlet, which method (doGet, doPost, etc) would end up called in the new servlet?
When a servlet receives a request it first handles it in it's service method. Service then calls the getMethod object of the request to find out which type of request this is and calls the appropriate method. Becuase the same request object is used in both servlets, the servlet forwarded to will handle the request with the same method that the forward-er did.
By the way: The same principals apply to your error page question. If you are going to use a servlet as your error page, you should implement both doPost and doGet. The simplest way to do this is to have doGet call doPost or vice verca.
In other words: If it was a POST request it will be handled in doPost. If it was a GET request, it will be handled in doGet. [ September 27, 2005: Message edited by: Ben Souther ]