I am trying to get the result from servlet (B) within servlet (A) and react to the result.
eg
in servlet B
response.getWriter().print("HELLO");
in servlet A
ServletContext context = this.getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher("/B");
dispatcher.include(request, response);
// if the response from B is "HELLO", then do something
What would be the best practice for the solution? or should the way it response in servlet B would be changed to other method?
you should use this method:
RequestDispatcher
URLConnection
or HTTPClient
redirect
getServletContext().getServlet(name)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.