Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect() Vs. include() Vs. forward()

 
Rajasekhar Karanam
Greenhorn
Posts: 16
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, Please make me clear about these topics in Servlets.
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sendRedirect(myUrl1) : you are sending back a response to the client and asking the browser to make a new request with the provided url, here myUrl1

include() : Say in servletA you call include(/path/to/myView.jsp) : you are asking the web container to include in the response of servletA the response of myView.jsp.
ServletA is in control, I mean responsible for generating the response to the client and you just include as well the response of another web component (e.g jsp)

forward() : say in servletA you call forward(path/to/myView.jsp): here servletA passes the control to myView.jsp to generated the response to the client. The client will see only the content from myView.jsp nothing from servletA.

I hope that helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic