${list[0].username}<br> ${list[1].username}<br> ${list[2].username}<br> <%List<TestUser> list = (List)request.getAttribute("list"); %><br> username:<%=list.get(0).getUsername() %><br> <c:forEach items="${list }" var="person"> c標簽username:${person.username }<br> </c:forEach>
${map.person1.username}<br> ${map["person2"].username }<br> ${map["1"].username }<br>
<c:if>和<c:when> <c:if>沒有<c:else>可以用<c:choose>來取代結構: <c:choose> <c:when test=""> 如果 </c:when> <c:otherwise> 否則 </c:otherwise> </c:choose> 在同一個 <c:choose> 中,當所有 <c:when> 的條件都沒有成立時,則執(zhí)行 <c:otherwise> 的本體內(nèi)容。 語法 <c:otherwise> 本體內(nèi)容 </c:otherwise> 屬性 無 限制 ·<c:otherwise> 必須在 <c:choose> 和 </c:choose>之間 ·在同一個 <c:choose> 中時,<c:otherwise> 必須為最后一個標簽 說明 在同一個 <c:choose> 中,假若所有 <c:when> 的test屬性都不為true時,則執(zhí)行 <c:otherwise> 的本體內(nèi)容。 范例 筆者舉一個典型的 <c:choose>、<c:when>和<c:otherwise>范例: <c:choose> <c:when test="${condition1}"> condition1為true </c:when> <c:when test="${ condition2}"> condition2為true </c:when> <c:otherwise> condition1和condition2都為false </c:otherwise> </c:choose> 范例說明:當condition1為true時,會顯示“condition1為true”;當condition1為false且condition2為true時,會顯示“condition2為true”,如果兩者都為false,則會顯示“condition1和condition2都為false”。 注意 假若condition1和condition2兩者都為true時,此時只會顯示"condition1為true",這是因為在同一個<c:choose>下,當有好幾個<c:when>都符合條件時,只能有一個<c:when>成立。
|