您的位置:首页 > Web前端 > JavaScript

JSTL表达式在项目中的使用

2015-05-05 14:25 197 查看
<td  class="text-center">
<c:choose>
<c:when test="${device.status == 1 }">InActive</c:when>
<c:when test="${device.status==0 }">Active</c:when>
<c:otherwise></c:otherwise>
</c:choose>

</td>

<td>
<c:choose>
<c:when test="device.crtTime==device.minTime">New Created</c:when>
<c:when test="${device.status==1&&device.crtTime==device.maxTime }">Logout</c:when>
<c:otherwise>Modify</c:otherwise>
</c:choose>

</td>

<c:forEach items="${modalities}" var="m">
<option value="${m.key}"><c:out value="${m.value}" /></option>

</c:forEach>

<fmt:formatDate value="${item.createDate}" pattern="yyyy-MM-dd"/></td>

<select name="year" id="year">

                <c:forEach var="ye" items="${years}" varStatus="vs">

                              <c:if test="${ye==year}">

                                              <option value="${ye}" selected=selected>${ye}</option>

                                </c:if>

                                <c:if test="${ye!=year}">

                                               <option value="${ye}">${ye}</option>

                                 </c:if>

                                          

                </c:forEach>

</select>

JSTL截取字符串

jstl1.1引入了一个fn.tld的标签,用于处理字符,如获得字符length,substring,indexof,endWith,lowcase
实现截取字符串

<c:set var="log.logTitle" value="做一个截取字符串长度的测试"
<c:choose> 
     <c:when test="${fn:length(log.logTitle) > 10}"> 
      <c:out value="${fn:substring(log.logTitle, 0, 10)}......" /> 
     </c:when> 
     <c:otherwise> 
      <c:out value="${log.logTitle}" /> 
     </c:otherwise>
 </c:choose>

JSTL获取map的值

<c:forEach var="delivery" items="${deliveryMap}">
<option value='<c:out value="${delivery.key }"></c:out>'><c:out value="${delivery.value }"></c:out></option>

</c:forEach>

jstl做判断

<c:choose>
<c:when test="${editItem.status==0}">
<option value="0"  selected="selected">Active</option>
</c:when>
<c:otherwise>
<option value="0">Inactive</option>
</c:otherwise>
</c:choose>

<c:choose>
<c:when test="${editItem.status==1}">
<option value="1"  selected="selected">Inactive</option>
</c:when>
<c:otherwise>
<option value="1">Inactive</option>
</c:otherwise>
</c:choose>

<c:forEach items="${labs }" var="lab">
<option value="${lab.locationid }" <c:if test="${ editItem.labId !=null&&lab.locationid eq editItem.labId }">selected=selected </c:if> > ${lab.labName}</option>

</c:forEach>

<td class="middle_title takeOff">
      <select name="takeOff"  id="takeOff" style="width:80%">
  <c:forEach var="takeOfforder" items="${order.allTakeOff}">
           <option value="${takeOfforder.key}" <c:if test="${takeOfforder.value eq order.takeOff}">selected="selected"</c:if>>${takeOfforder.value}</option>
  </c:forEach>
  </select>
   </td>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jstl