The resource requested by the RequestDispatcher is available and implemented by the DestinationServlet.
//From file SourceServlet.java
public class SourceServlet extends HttpServlet{
public void service(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
ServletContext cxt=getServletConfig().getServletContext();
RequestDispatcher rd=cxt.getRequestDispatcher("/destn");
response.getWriter().println("hello from source");
response.flushBuffer();
rd.forward(request,response);
}
}
//From file DestinationServlet.java
public class DestinationServlet extends HttpServlet{
public void service(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.getWriter().println("hello from dest");
response.flushBuffer();
}
}
What is the result?
A. An exception is thrown at runtime by SourceServlet.
B. An exception is thrown at runtime by DestinationServlet.
C. Only “hello from dest” appears in the response output stream.
D. Both “hello from source” and “hello from dest” appear in the response output stream.