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

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.

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 – 2022 BeginnersBook . Privacy Policy . Sitemap