BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

JSTL <c:redirect> Core Tag

Last Updated: November 30, 2013 by Chaitanya Singh | Filed Under: JSTL

<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.

Top Related Articles:

  1. JSTL <c:catch> Core Tag
  2. JSTL <c:import> Core Tag
  3. JSTL <c:url> Core Tag
  4. JSTL <c:out> Core Tag
  5. JSTL <c:set> Core Tag

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

JSTL Core Tags

  • c:out
  • c:set
  • c:remove
  • c:if
  • c:choose
  • c:when
  • c:otherwise
  • c:catch
  • c:import
  • c:forEach
  • c:forTokens
  • c:param
  • c:url
  • c:redirect
JSTL Functions
  • fn:contains()
  • fn:containsIgnoreCase()
  • fn:indexOf()
  • fn:escapeXML()
  • fn:join() & fn:split()
  • fn:length()
  • fn:startsWith()
  • fn:endsWith()
  • fn:substring()
  • fn:substringAfter()
  • fn:substringBefore()
  • fn:trim()
  • fn:toUpperCase()
  • fn:toLowerCase()
  • fn:replace()

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap