Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

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
0
jkavx
Asked:
jkavx
  • 2
1 Solution
 
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
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now