Forward Action Tag

The jsp:forward action tag is used to forward the request to another resource it may be jsp, html or another resource.


Syntax of jsp:forward action tag without parameter
<jsp:forward page="relativeURL | <%= expression %>" />


Syntax of jsp:forward action tag with parameter
<jsp:forward page="relativeURL | <%= expression %>" >
<jsp:param name="parametername" value="parametervalue | <%=expression%>" />
</jsp:forward>


Example of jsp:forward action tag without parameter

In this example, we are simply forwarding the request to the printdate.jsp file.

index.jsp
<html>
<body>
<h2>this is index page</h2>
<jsp:forward page="printdate.jsp" />
</body>
</html>

printdate.jsp
<html>
<body>
<% out.print("Today is:"+java.util.Calendar.getInstance().getTime()); %>
</body>
</html>

Example of jsp:forward action tag with parameter

In this example, we are forwarding the request to the printdate.jsp file with parameter and printdate.jsp file prints the parameter value with date and time.

index.jsp
<html>
<body>
<h2>this is index page</h2>

<jsp:forward page="printdate.jsp">
<jsp:param name="name" value="silantutorial.com" />
</jsp:forward>

</body>
</html>

printdate.jsp
<html>
<body>
<% out.print("Today is:"+java.util.Calendar.getInstance().getTime()); %>
<%= request.getParameter("name") %>
</body>
</html>

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext