JSP forward and include tag

tutorial and example
tutorial and example

In JSP, forward and include tags are the most frequently used action tags. Unlike Servlets, there is no need to create object of RequestDispatcher interface to use the functionality of forward and include. Thus, JSP provides direct tag for the same purpose.

JSP forward Tag

In JSP, forward tag terminates the execution of current JSP page and forward the control to new page which can be JSP, Servlet, HTML or any other. The response of new page is displayed to the user.

Syntax: –

JSP include Tag

The role of include tag is to dispatch the external resource in the JSP page. The external resource can be JSP, Servlet HTML or any other page. 

Syntax: –

Example of forward and include Tag

This example represents the functionality of both, forward and include tag.

index.jsp

CheckPage.jsp

WelcomePage.jsp

Error.jsp

Output

The entered password must be more than 4 digits.

Enter a strong password (i.e. more than 4 digits) to see welcome page.