RequestDispatchar in Java, What is RequestDispatchar?

It is used to navigate application content from the web server without using a web browser.

RequestDisptchar  Provide better performance as compare to redirect().

It contain navigation from JSP to Servlet or Servlet to Servlet.


redirect() is also used to navigation from JSP to Servlet and Servlet to Servlet but it completes roundtrip from server to client then the client to another page.


It has two different methods for Page Redirection:-

1) Forward:-

   It is used to forward a request from one servlet to another without using URL because it will directly forward application content from Server.

   Syntax
    RequestDispatcher req=  request.getRequestDispatcher("Servlet2");
    req.forward(request, response);


URL Will not be changed it will show Servlet1 but it has forwarded to servlet2:-

http://localhost:8080/WebConept3/Servlet1



Limitation :-  we can not handle client side state management option because it will directly send data from server end.





2)  Include:-

     It is used to merge the request of Servlet2 content into Servlet1 content.

     It is similar to include tag of JSP.


    http://localhost:8080/WebConept3/Servlet1


Url will not change only content of servlet2 will be merged into servlet1

It will also not use Cookie or Client Side State Management Option.






RequestDisptachar interface will be used to server-side navigation from one Servlet to another Servlet.






Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post