Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in understanding of Request Dispatcher

 
Daksh Mital
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
Can nebody help me with the output of the following code snippet.

Consider the following code snippets.

In the doGet() of FirstServlet:
PrintWriter out = response.getWriter();
out.println("<html><body>Page 1");
RequestDispatcher rd = request.getRequestDispatcher("NextServlet");
rd.forward(request, response);
out.println("
Page 3</body></html>");

In the doGet() of SecondServlet:
PrintWriter out = response.getWriter();
out.println("
Page 2");

What will be displayed on the browser when a GET request is sent to FirstServlet assuming that the buffer is large enough to hold all the data before sending the data to the client?

Am confused with how the RequestDispatcher forward() mechanism works out.
Does it delegate the request and response object completely or what??
Please help
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.

Why not just run it and see what happens? It'd be substantially quicker than waiting for someone to answer your question.

You might also find some information regarding this on the internet. While your results will vary, when I ran this search several of the top hits were direct answers to your question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic