How is it possible to call doGet()
method from RequestDispatcher
?
RequestDispatcher rd = sc.getRequestDispatcher("/CartServlet");
rd.forward(request, response);
This code calls doPost()
as the default action.
It calls doPost()
because your original request used POST method.
Generally servlets cannot "call" each other. They just can forward or redirect request. In both cases the same HTTP method that was used in original request is used.
If you want to call doGet()
of other servlet it is the time to refactor your application, i.e. separate the logic implemented in doGet()
, put it to other class and call this class from both servlets.