Skip to content

Files

Latest commit

 

History

History
37 lines (28 loc) · 1.17 KB

16.md

File metadata and controls

37 lines (28 loc) · 1.17 KB

JSTL<c:redirect>核心标签

原文: https://beginnersbook.com/2013/11/jstl-credirect-core-tag/

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

语法:

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

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

在这里,我们根据变量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