学到 jstl语言的几点注意事项

1.当要在jsp中使用两个条件都是真的时<c:when test="${empty current.procureNew&&current.userByCreater.id==user.id}">,例子如下:

 <c:choose><c:when test="${empty current.procureNew&&current.userByCreater.id==user.id}">
     <a title="<fmt:message key="navigation.edit" />" href="${pageContext.request.contextPath}/updateProjectProcure?idKey=${current.id}&"><img src="${pageContext.request.contextPath}/images/icons/edit.gif" /></a>    
 <a title="<fmt:message key="navigation.delete" />" href="${pageContext.request.contextPath}/deleteOldProjectProcure?id=${current.id}&" onclick='return confirm("<fmt:message key="confirm.if.delete"/>")'><img src="${pageContext.request.contextPath}/images/icons/delete.gif" /></a>
   &nbsp;
    </c:when><c:otherwise></c:otherwise>
    </c:choose>
2.当需要判断一个字段为空时,例如判断一个字符串为空时,<c:when test="${current.memo==null}">

当需要判断的一个对象为空时,则代码如下<c:when test="${empty current.procureNew}">

3.当你觉得<c:choose><c:when></c:when><c:otherwise></c:otherwise></c:choose>来做判断选择不足够时,你可以使用以下的方式:<c:choose><c:when test='${newFlag}'>
<c:if test="${current.enabled==true}"><a href="#" onclick="hit('${current.id}','${current.enabled}');"><fmt:message key="disable" /></a></c:if>
<c:if test="${current.enabled!=true}"><a href="#" onclick="hit('${current.id}','${current.enabled}');"><fmt:message key="enable" /></a></c:if>
   </c:when>
   <c:otherwise>
   <c:if test="${current.enabled==true}"><a href="${pageContext.request.contextPath}/disableOtherUser?idKey=${current.id}&"><fmt:message key="disable" /></a></c:if>
<c:if test="${current.enabled!=true}"><a href="${pageContext.request.contextPath}/enableOtherUser?idKey=${current.id}&"><fmt:message key="enable" /></a></c:if>
   &nbsp;
   </c:otherwise></c:choose>

4、<c:choose><c:when>

<c:choose><c:when></c:when><c:otherwise></c:otherwise></c:choose></c:when>

<c:otherwise><c:choose><c:when></c:when><c:otherwise></c:otherwise></c:choose></c:otherwise></c:choose>这种样式是错误的。

你可能感兴趣的:(jstl,c:if,c:choose,对象或字段为空,两个条件时)