This tag <c: redirect> redirects or forward to other URL or alternative URL provided in the condition. It also supports <c: param> tag some attributes are also use to make it proper like “URL” Attribute this will use to redirect the browser to other web page.
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>
<html>
<head>
<title><c:redirect>Tag Example In J.S.P</title>
</head>
<body>
<p><b><br><center>
<c:set var=”age” scope=”request” value=”18″/>
<c:if test=”${age>=18}”>
<c:redirect url=”canvote.jsp”/>
</c:if>
<c:if test=”${age<18}”>
<c:redirect url=”cantvote”/>
</c:if>
</p></b></br></center>
</body>
</html>
This Program will execute if the condition goes true it will redirect to another page that will show the message “You Can vote” otherwise will skip to other web page that will show “You can’t vote”.
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>
<html>
<head>
<title>Vote Eligible</title>
</head>
<body>
<p><center><br><b>
<c:out value=”You Can Vote…”/>
</b></br></center></p>
</body>
</html>
False condition URL page will be redirect as below …
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>
<html>
<head>
<title>Vote Eligible</title>
</head>
<body>
<p><center><br><b><c:out value=”You Can’t Vote…”/></b></br></center></p>
</body>
</html>