Tuesday, June 26, 2018

Request Dispatcher

  • The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp.
  • This interface can also be used to include the content of another resource also. It is one of the way of servlet collaboration.  

Two Methods of Request Dispatcher:
  1. Forward
  2. Include

    Syntax:
              RequestDispatcher rd = request.getRequestDispatcher("/URL Pattern of Destination Servlet");
              rd.forward(request,response);   //Forward
              rd.include(request,response);    //Include
     
    Send Redirect
    • The sendRedirect() method of HttpServletResponse interface can be used to redirect response to another resource, it may be servlet, jsp or html file.  

    Syntax:
              response.sendRedirect("/URL Pattern of Destination Servlet");    //Redirect


    forward() method
    sendRedirect() method
    The forward() method works at server side.
    The sendRedirect() method works at client side.
    It sends the same request and response
    objects to another servlet.
    It always sends a new request.
    It can work within the server only.
    It can be used within and outside the server.


    Note: 
    • In Forward and Include, the URL will not change.
    • In Redirect URL will be changed.

    No comments:

    Post a Comment