I want to forward a request to multiple servlets in Java. Each of those servlets will perform their own operations after receiving the request.
My current code is doing this:
for(int i=0; i < numServlets; i++) {
ServletContext servletContext = request.getServletContext();
RequestDispatcher requestDispatcher = servletContext.getRequestDispatcher("/"+ globalVars.ServletList[i]);
requestDispatcher.forward(request, response);
}
The problem is I am getting `java.lang.IllegalStateException:
Cannot forward after response has been committed
error.
Any ideas on how to make this work?
I read online that after forwaring the request I should add return
statement to let the following code execute, but that did not work either.