aspose file tools*
The moose likes Servlets and the fly likes sendRedirect() Vs. include() Vs. forward() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "sendRedirect() Vs. include() Vs. forward()" Watch "sendRedirect() Vs. include() Vs. forward()" New topic
Author

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

Rajasekhar Karanam
Greenhorn

Joined: Sep 18, 2011
Posts: 15

Guys, Please make me clear about these topics in Servlets.
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180

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


SCJP 5 , SCWCD 5, SCEA 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sendRedirect() Vs. include() Vs. forward()