difference between forward() and include of requestDispatcher ?

Discussions

Web tier: servlets, JSP, Web frameworks: difference between forward() and include of requestDispatcher ?

  1. Hi,
    can anybody tell me the difference of requestDispatcher.forward() and requestDispatcher.include()?

    and where to use which one ?
    thanks in advance.
    dipes.

    dipes.biswas@wipro.com
  2. hi dipes,

    will difference is in their name itself.

    forward is used to forward a request, that is control is transfered to the new servler/jsp. u shud take care to not put any our.println() statements in the servlet from where u plan to call forward method. in fact u cant even fire response.getWriter() method in this case. u can only do that in the servlet to which the control is bein fwded


    include - means that the new servlet/jsp will be procesed and any out.println()/html stuff will be included and then control will come back to the servlet/jsp that called include method.

    hope this helps

    kapil
  3. Thanks Kapil.
    Yes, this is all I wanted.
  4. one doubt !![ Go to top ]

    but does this mean that forward () does not send control back to this current servlet(where we hav executed our forward call) after procesing jsp/class. ??
  5. ![ Go to top ]

    but does this mean that forward ()
    does not send control back to this current servlet(where we hav executed our forward call) after procesing jsp/class. ??


    Dude, that is not possible, it's java after all. Control will comeback but it just means that you cannot modify the stream.

    Guru