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
jkavxAsked:
Who is Participating?
 
aozarovCommented:
Two corrections:
1. Typo: from your httpservletrquest obtain RequestDispatcher
2. subclass HttpServletResponseWrapper and pass to the RequestDispatcher (instead of
ServletResponseWrapper)

For example of how to use the HttpServletResponseWrapper see http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets8.html
The link explains how to use it with Filter but the concept is the same.
0
 
aozarovCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.