Link to home
Start Free TrialLog in
Avatar of jkavx
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
Avatar of aozarov
aozarov

You can try this API calls:
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.ServletResponse)
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
ASKER CERTIFIED SOLUTION
Avatar of aozarov
aozarov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial