<c:redirect> is used for redirecting the current page to another URL.
Syntax:
<c:redirect url="http://www.anydomainhere.com/samplepage.jsp"/>
This is how the <c:redirect> tag looks like. We just need to provide the relative address in the URL attribute of this tag and the page will automatically be redirected the URL provided when it gets loaded.
Example
Here we are redirecting the page to a different url based on the value of the variable myurl. If the value is 1 page will be redirected to https://beginnersbook.com and for 2 it will go to http://www.google.com.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title> JSTL c:redirect Tag Example</title> </head> <body> <c:set var="myurl" value="2" scope="request"/> <c:if test="${myurl<1}"> <c:redirect url="https://beginnersbook.com"/> </c:if> <c:if test="${myurl>1}"> <c:redirect url="http://www.google.com"/> </c:if> </body> </html>
Output: Since the value of the variable myurl is 2 the page gets directed to the http://www.google.com.