What’s the Difference between Forward and Include tags?

The Forward action enables you to forward the request to a static HTML file, a servlet, or another JSP. The syntax is <jsp:forward page=”url” />
The JSP that contains the Forward action first stops processing then clears its buffer, and forwards the request to the target resource. The calling JSP should not write anything. It will first execute the response and then It will execute the rest of its’ actions.
Include is another frequently used tag. There are two types of Include options: the include directive and the include action.
The include directive executes when the JSP is compiled. IT parses any JSP elements in the included file for a static result that is the same for every instance of that JSP. The syntax for the include directive is <@ include file=”some-filename” %>.
The include action, on the other hand, executes for each client request of the JSP, which means the file is not parsed but included in place. This provides the capability to dynamically change not only the content that you want to include, but also the output of that content. The syntax for the include action is <jsp:include page=”some-filename” flush=”true” />. Note that the flush attribute must always be included (in JSP 1.1) to force a flush of the buffer in the output stream.

Posted in JSP | Tagged | Leave a comment