You are here:   HomeJava Server PagesJava Standard Tag Lib (JSTL)JSTL Core c redirect Tag

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>&lt;c:redirect&gt;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>

                       JSTL Core c redirect Tag

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>





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Search Content







Advance Courses



Basic Courses



Advertise with Us