jstl c:choose、c:when和c:otherwise标签的简单使用介绍
生活随笔
收集整理的這篇文章主要介紹了
jstl c:choose、c:when和c:otherwise标签的简单使用介绍
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<c:choose>、<c:when>和<c:otherwise>在一起連用,可以實現Java語言中的if-else語句的功能。例如以下代碼根據username請求參數的值來打印不同的結果:<c:choose> <c:when test="${empty param.username}"> Nnknown user. </c:when> <c:when test="${param.username=='Tom'}"> ${param.username} is manager. </c:when> <c:otherwise> ${param.username} is employee. </c:otherwise> </c:choose> 以上標簽等價于以下Java程序片段:<% String username=request.getParameter("username"); if(username==null){ //對應第一個<c:when>標簽的主體
out.print("Nnknown user."); }else if(username.equals("Tom")){ //對應第二個<c:when>標簽的主體
out.print(username+" is manager."); }else{ //對應<c:otherwise>標簽的主體
out.print(username+" is employee."); } %> <c:choose>、<c:when>和<c:otherwise>標簽的使用必須符合以下語法規則:<c:when>和<c:otherwise>不能單獨使用,它們必須位于<c:choose>父標簽中。在<c:choose>標簽中可以包含一個或多個<c:when>標簽。在<c:choose>標簽中可以不包含<c:otherwise>標簽。在<c:choose>標簽中如果同時包含<c:when>和<c:otherwise>標簽,那么<c:otherwise>必須位于<c:when>標簽之后。
?
轉載于:https://www.cnblogs.com/yuanchaoyong/p/7111707.html
總結
以上是生活随笔為你收集整理的jstl c:choose、c:when和c:otherwise标签的简单使用介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VC下调用x264进行视频编码,
- 下一篇: sqluldr2导出过blob字段_转载