Computer >> Computer tutorials >  >> Programming >> Programming

What is the use of <c:redirect > tag in JSP?


The <c:redirect> tag redirects the browser to an alternate URL by facilitating automatic URL rewriting, it supports context-relative URLs, and it also supports the <c:param> tag.

Attribute

The <c:redirect> tag has the following attributes −

AttributeDescriptionRequiredDefault
urlURL to redirect the user's browser toYesNone
context/ followed by the name of a local web applicationNoCurrent application

Example

If you need to pass parameters to a <c:import> tag, use the <c:url> tag to create the URL first as shown below −

<%@ taglib uri = "https://java.sun.com/jsp/jstl/core" prefix = "c" %>
<html>
   <head>
      <title><c:redirect> Tag Example</title>
   </head>
   <body>
      <c:redirect url = "https://www.photofuntoos.com"/>
   </body>
</html>

The above code will redirect the request to https://www.photofuntoos.com - Try it yourself.