The forward action terminates the action of the current page and forwards the request to another resource such as a static page, another JSP page, or a Java Servlet.
General syntex of JSP Forward Tag look like this:
JSP Forward Tag Example:
<jsp:forward page="Relative URL" />
Explanation: As shown above, forward tag in JSP has only one attributes “page”.
page Attribute: page attribute in JSP Forward Tag specifies the relative path of the source where request is going to be handled. This file can be any html, servlet or jsp file.
Let us reuse following two files
(a) header.jsp and
Following is the content of index.jsp file:
<html> <head> <title>The include Action Example</title> </head> <body> <center> <h2>The include action Example</h2> <jsp:forward page="header.jsp" /> </center> </body> </html>
<p> Today's date: <%= (new java.util.Date()).toLocaleString()%> </p>
Now let us keep all these files in root directory and try to access index.jsp. This would display result something like as below. Here it discarded content from main page and displayed content from forwarded page only.