jsp中jstl標簽的類似 if - else 語句 的語法


在jsp中引入jstl的標簽庫和函數庫

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

1. jsp中傳遞參數,經過action,存儲到request中

<area shape="poly" coords="680,111,765,82,811,196,724,223" 

 href="${pageContext.request.contextPath}/news/queryNews.do?artType=9&new=3" alt="攝影" title="攝影" />

2. java代碼中有

String newFlag=request.getParameter("newFlag");
  if(newFlag!=null && !newFlag.equals("")){
   request.setAttribute("newFlag",newFlag);
  }

3. jsp中的類似  if - else 語句 的語法

<c:choose>
   <c:when test="${requestScope.newFlag== '1' || requestScope.newFlag== '2' ||requestScope.newFlag== '3'}"> 
         作品名稱: ${star.class_}<br />
         作品編號: ${star.raceNum}<br />       
   </c:when>
   <c:otherwise>
     班級: ${star.class_}<br />
     參賽編號: ${star.raceNum}<br />
   </c:otherwise>
</c:choose>

 

1. 如果在jsp中傳遞參數,沒有經過action ,直接跳轉到jsp頁面

<a href="${pageContext.request.contextPath}/reg.jsp?newFlag=${requestScope.newFlag}">

<img src="${pageContext.request.contextPath}/images/reg.png" width="76" height="53" alt="我要注冊" title="我要注冊" />

</a>

2. 在jsp中取得jsp傳過來的參數,此時要使用${param.newFlag}

<c:choose>
   <c:when test="${param.newFlag== '1' || param.newFlag== '2' ||param.newFlag== '3'}"> 
    <th>作品名稱<font color="Red">*</font>:</th>      
   </c:when>
   <c:otherwise>
   <th>班級<font color="Red">*</font>:</th>
   </c:otherwise>
</c:choose>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM