Forward() : This can be done in two ways by Request & ServeletContext. Forwarding a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. Forward is done at server side, without the client's knowledge.
When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container.
Simply
include: will include another file in our current file
forward: will forward the current request to the forwarding page
The difference between the two tags is that the way they work. Well, I will say an example so that you can imagine it better.
Assume you have two pages, pageA, and pageB. In pageA you wrote the include tag. In this case the control was in pageA til you called the include tag. At this point the full control goes to pageB. When It's done, control is returned to pageA starting from the next point of coding after the include tag and continuing to the rest of pageA.
Well, to get things much clearer, let's say that we have the same pages, pageA and pageB, but this time we will use the forward tag in pageA, not the include tag. Again, the control will begin in pageA till we call the forward tag in pageA, at this point, control is transfered to pageB, just like the include tag. But the difference is what happens when pageB completes. In case of the forward tag, control doesn't go back to pageA again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With