Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

RequestDispatchar in Java, What is RequestDispatchar?

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

RequestDisptchar Interface  Provide better performance as compare to redirect() but we can not manage browser state using session and cookies.URL will not change in Requestdispatcher Interface.


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


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 hence it will manage browser state using session and cookies and URL will change.



Requestdispatcher has two different methods for Page Redirection:-

1) Forward:-

 It is used to forward a request from one servlet to another without changing the URL because it will directly forward application content from Server to 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 the client-side state management option means session and cookie because it will directly send data from the server end.





2)  Include:-

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

     It is similar to include the 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 for server-side navigation from one Servlet to another Servlet or Servlet to JSP.






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