Hi everyone,
Is there any possibility that we can call a servlet from another servlet after receiving the response from the first servlet.
Note: Both the servlets are of POST method and both are of Path based servlets.
Please provide your inputs on this.
Regards,
Sravani
Solved! Go to Solution.
Views
Replies
Total Likes
You can call the servlet programmatically from another servlet in one of two ways, as per [1].
To include another servlet's output, use the include() method from the RequestDispatcher interface. This method calls a servlet by its URI and waits for it to return before continuing to process the interaction. The include() method can be called multiple times within a given servlet.
For example:
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/servlet/ShowSupplies"); dispatcher.include(request, response); |
To handle interaction control to another servlet, use the RequestDispatcher interfaces forward() method with the servlet's URI as a parameter.
This example shows a servlet using forward():
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/servlet/ShowSupplies"); dispatcher.forward(request, response); |
Here is the reference
[1] https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
Hope this help!
You can call the servlet programmatically from another servlet in one of two ways, as per [1].
To include another servlet's output, use the include() method from the RequestDispatcher interface. This method calls a servlet by its URI and waits for it to return before continuing to process the interaction. The include() method can be called multiple times within a given servlet.
For example:
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/servlet/ShowSupplies"); dispatcher.include(request, response); |
To handle interaction control to another servlet, use the RequestDispatcher interfaces forward() method with the servlet's URI as a parameter.
This example shows a servlet using forward():
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/servlet/ShowSupplies"); dispatcher.forward(request, response); |
Here is the reference
[1] https://docs.oracle.com/cd/E19146-01/819-2634/abxbn/index.html
Hope this help!
Hi,
Generally we don't do that. The best way to handle this kind of situation to encapsulate the logic in osgi service/component and reference these services in servlet.
So no need to make additional request.
Now Your servlet can refer both services