File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Problem in understanding of Request Dispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in understanding of Request Dispatcher" Watch "Problem in understanding of Request Dispatcher" New topic

Problem in understanding of Request Dispatcher

Daksh Mital

Joined: Aug 19, 2007
Posts: 19
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);
Page 3</body></html>");

In the doGet() of SecondServlet:
PrintWriter out = response.getWriter();
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

Joined: Sep 29, 2008
Posts: 12617

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.
I agree. Here's the link:
subject: Problem in understanding of Request Dispatcher
It's not a secret anymore!