• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RequestDispatcher include and forward

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could anyone tell me the difference between
req.getRequestDispatcher("try.jsp" ).forward(req ,resp)
and
req.getRequestDispatcher("try.jsp" ).include(req ,resp);

Thanks in advance
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did you not understand after reading the JavaDoc for these methods?
 
pankaj kapoor
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what I have understood is that both of the methods direct to the JSP file mentioned in the method argument. ie include or forward.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think after forward you are pretty much done with request/response and can't use it anymore to change content received by a browser. In case of include you can.
 
pankaj kapoor
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still not clear with your comment

'I think after forward you are pretty much done with request/response and can't use it anymore to change content received by a browser. In case of include you can.
'
could you elaborate on it.
 
Ranch Hand
Posts: 328
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello PAnkak,
forward
Once you forward the request from say Servlet A to any other Servlet/JSP control gets transferred from Servlet A to forwarded patrty & it never returns back to A for that request.
Include
In include what you are doing is if Servlet A(Above example) is including the response of other Servlet/JSP(say B or B.jsp) so momentarily Control goes to B or B.jsp (they will genrate the response) control comes back to A & generated response is added in A's Response.


I hope this helps....feel free if you need more explanation.
Shinivas
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just updated the servlet FAQ. You can find it here
 
reply
    Bookmark Topic Watch Topic
  • New Topic