jkavx
asked on
Call servlets from controller servlet
I need to be able to call n number of servlets from a controller servlet, and build a final html string by handling the response from each of the servlet calls. How do I call these servlets from the controller servlet?
Thx.
jkavx
Thx.
jkavx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1. from your httpservletrquest obtain getRequestDispatcher -> http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletRequest.html#getRequestDispatcher
2. for each servlet you want to invoke call -> http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/RequestDispatcher.html#include(javax.servlet.ServletRequest, javax.servlet.ServletRespo
Where you can wrap the Servlet response with a subclass of ServletResponseWrapper (so you can take the servlet response back the same way Filter does) -> http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponseWrapper.html