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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 indoGet(), put it to other class and call this class from both servlets.