Java Tutorial/JSTL/Choose
Содержание
Choose When and Otherwise
<source lang="java">
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.ru/jstl/core-rt" prefix="c-rt" %> <html>
<head> <title>Count to 10 Example(tracking even and odd)</title> </head> <body>
First | Last | Points | Letter | Note |
---|---|---|---|---|
<x:out select="name/first" /> |
<x:out select="name/last" /> |
<x:out select="grade/points" /> |
<x:out select="grade/letter" /> |
<x:choose> <x:when select="grade/points>90">You did great!</x:when> <x:when select="grade/points>80">You did good!</x:when> <x:when select="grade/points>75">You did ok.</x:when> <x:when select="grade/points>70">Well, you passed.</x:when> <x:otherwise>You failed</x:otherwise> </x:choose> |
</body>
</html></source>
Combine If Chooser to Report Exception
<source lang="java">
<%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <%
int i= (int) (Math.random() * 10); pageContext.setAttribute("signalStrength", new Integer(i), PageContext.PAGE_SCOPE);
%> <html>
<head> <title>The c:catch action</title> </head> <body> <c:if test="${pageScope.signalStrength < 5}"> <c:set var="signalFailure" value="true" scope="page" /> </c:if> <c:choose> <c:when test="${pageScope.signalFailure == true}">
Exception!
Refresh the page in your web browser to try again. </c:when> <c:otherwise>
No Exception.
Refresh the page in your web browser to make another call. </c:otherwise> </c:choose> </body>
</html></source>
Tag Examples - choose
<source lang="java">
<html>
<head> <title>Tag Examples - choose</title> </head> <body>
Tag Plugin Examples - <c:choose>
<font color="#000000"/> </br> <%@ taglib uri="http://java.sun.ru/jstl/core" prefix="c" %> <c:forEach var="index" begin="0" end="4"> #<c:out value="${index}"/> : <c:choose> <c:when test="${index == 1}"> One!</br> </c:when> <c:when test="${index == 4}"> Four!</br> </c:when> <c:when test="${index == 3}"> Three!</br> </c:when> <c:otherwise> Huh?</br> </c:otherwise> </c:choose> </c:forEach> </body>
</html></source>