<c:if>-Tag
Das <c:if>-Tag wertet den Wert eines Ausdrucks aus. Wenn der Wert des Ausdrucks wahr ist, führt es seinen Body-Inhalt aus.
Syntaxformat
<c:if test="<boolean>" var="<string>" scope="<string>"> ... </c:if>
Attribute
Das <c:if>-Tag hat die folgenden Attribute:
| Attribute | Beschreibung | Erforderlich | Standardwert |
|---|---|---|---|
| test | Bedingung | Ja | Keine |
| var | Variable, die zum Speichern des Ergebnisses der Bedingung verwendet wird | nein | Keine |
| scope | Gültigkeitsbereich des var-Attributs | nein | page |
Demo-Beispiel
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:if 标签实例</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>我的工资为: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
Die Ausgabe sieht wie folgt aus:
我的工资为: 4000
Andere Erweiterungen
JSP-Standard-Tag-Bibliothek