Latest web development tutorials

<C: choose>, <c: when>, <c: otherwise>

JSP Standard Tag Library JSP Standard Tag Library

<C: choose> y la función de instrucción switch Java como para tomar una decisión en un número de opciones.

sentencia switch tiene un caso, pero <c: choose> tiene un correspondiente <c: when>, sentencia switch con un valor predeterminado, y <c: choose> en <c: otherwise>.

sintaxis

<c:choose>
    <c:when test="<boolean>"/>
        ...
    </c:when>
    <c:when test="<boolean>"/>
        ...
    </c:when>
    ...
    ...
    <c:otherwise>
        ...
    </c:otherwise>
</c:choose>

propiedad

  • <C: choose> etiqueta no presenta atributos.
  • <C: cuando> tiene un solo atributo, han dado en la tabla siguiente.
  • <C: de otro modo> etiqueta no presenta atributos.

<C: cuando> propiedades de la etiqueta de la siguiente manera:

propiedad descripción Si es necesario defecto
prueba condición es no

Los ejemplos de demostración

<%@ 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:choose 标签实例</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<p>你的工资为 : <c:out value="${salary}"/></p>
<c:choose>
    <c:when test="${salary <= 0}">
       太惨了。
    </c:when>
    <c:when test="${salary > 1000}">
       不错的薪水,还能生活。
    </c:when>
    <c:otherwise>
        什么都没有。
    </c:otherwise>
</c:choose>
</body>
</html>

Los resultados son como sigue:

你的工资为 : 4000

不错的薪水,还能生活。

JSP Standard Tag Library JSP Standard Tag Library