JSTL c:redirect Core Tag

The JSTL <c:redirect> Core Tag is used to redirect the client’s browser to the specified url. It supports the <c:param> tag.

Syntax:

<c:redirect url=”relUrl” />

c:redirect tag attributes:

Attribute Description Required
url It specify the URL to redirect the user’s browser to. Yes
context / followed by the name of a local web application. No

Example:

test.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 
<html>
	<head>
		<title>c:redirect JSTL core tag example</title>
	</head>
	<body>
		<c:redirect url="/hello.jsp"/>
	</body>
</html>

hello.jsp

<html>
	<head>
		<title>c:redirec JSTL core tag example</title>
	</head>
	<body>
		<h3>This is a c:redirec JSTL core tag example.</h3>
	</body>
</html>

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>

Output:

jsp example 42
 
Download this example.
 
Next Topic: JSTL Formatting Tags with example.
Previous Topic: JSTL c:param Core Tag with example.