JSTL c:redirect 核心标签

JSTL <c:redirect>用于将当前页面重定向到另一个 URL。

<c:redirect> 语法:

<c:redirect url="http://www.anydomainhere.com/samplepage.jsp"/>

这是<c:redirect>的方式。标签看起来像。我们只需要在此标签的 URL 属性中提供相对地址,页面将自动重定向加载时提供的 URL。

<c:redirect> 示例

在这里,我们根据变量myurl的值将页面重定向到不同的 URL。如果值为 1,则页面将重定向到http://beginnersbook.com,对于 2,它将转到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="http://beginnersbook.com"/>
  </c:if>
  <c:if test="{myurl>1}">
     <c:redirect url="http://www.google.com"/>
  </c:if>
</body>
</html>

输出:由于变量myurl的值为 2,因此页面将定向到http://www.google.com

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程