what is request dispatcher and how does it work?

Answer Posted / mahesh bolla

Request dispatcher is used to transfer the same rquest to
another page/servlet without user interaction.
Exampe:
Suppose we have 2 servlets.
Write the below code in first Servlet

----
----
RequestDispatchet rd = request.getRequestDispatcher
("/secondServlet");
rd.forward(request, response);
//or rd.include(request, response);

---
----
Similar thing can be done in JSPs also

Write the below code in one.jsp

<js:forward page="two.jsp"/>
or
<jsp:include page="two.jsp");

If we use "forwad" then request will transfered to the
second page but not returned back to first page. We can see
only the second page's output.

If we use "include" then the sencond page itself will be
included in the first page. Then the output is the
combination of both the pages.

Is This Answer Correct ?    34 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference amongst jvm spec, jvm implementation, jvm runtime ?

500


Does treeset use compareto?

533


Can we use a default constructor of a class even if an explicit constructor is defined?

644


Can you explain the private protected field modifier?

565


What are the different tags provided in jstl?

543






What does this () mean in constructor chaining concept?

552


What is widening and narrowing in java? Discuss with an example.

554


What is flush () in java?

550


What is generic class?

642


What is final, finally, finalize?

590


What is re-factoring in software?

569


How will you calculate the depth of a binary tree if the tree contains 15 nodes?

593


You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain

526


How are multiple inheritances done in Java?

614


What purpose do the keywords final, finally, and finalize fulfill?

608