现在的位置: 首页 > 综合 > 正文

使用

2017年12月20日 ⁄ 综合 ⁄ 共 1334字 ⁄ 字号 评论关闭

今天写程序时,需要根据active值的不同,分别显示“开始”或“停止”,而且是在jsp中完成,不是在js文件中用javascript。因此用到了Core标签库中的if和choose。

  因为用普通的if else无法获得html标签中的值,所以用了<c:if>获得值来进行判断,其用法如下;

<c:if test=”${user.visitCount==1}”>  
       This is your first visit .  
</c:if>  

 因为<c:if>没有else语句,而我需要用到else的情况,因此可以使用<c:choose>,其用法如下:

<c:choose>  
  
    <c:when test="${sessionScope.USERTYPE == 'inner'}">  
  
      <c:set value="${context_root}/igmgr/MEB004.dow" var="action" scope="page"/>  
  
    </c:when>  
  
    <c:when test="${sessionScope.USERTYPE == 'merc'}">  
  
      <c:set value="${context_root}/igmgr/MEB021.dow" var="action" scope="page"/>  
  
    </c:when>    
  
   <c:otherwise>    
  
      <c:set value="${context_root}/igmgr/MEB020.dow" var="action" scope="page"/>  
  
   </c:otherwise>  
  
  </c:choose>  

core标签库还有其他的标签,例如:<c:out>
、 <c:set> 、 <c:remove> 、 <c:cath>,这些没有用到,所以不太熟悉。

  写好的程序如下:

<c:forEach var="sample" items="${sampleList}">  
   <tr>  
    <td >${sample.spotNum}</td>  
        <td >${sample.dev_code}</td>  
        <td>${sample.dust}</td>  
        <td>${sample.noise}</td>  
        <td>${sample.wind_direct}</td>  
        <td>${sample.wind_speed}</td>  
        <td>${sample.temp}</td>  
        <td>${sample.humid}</td>  
        <td>${sample.time}</td>  
        <td>${sample.rain_stat}</td>  
        <td>${sample.motor_speed}</td>  
        <td>${sample.bat_volt}</td>  
        <td>${sample.laser_inten}</td>  
        <td>${sample.bat_mod}</td>  
        <td>${sample.active}</td>  
     
        <c:choose>  
           <c:when test="${sample.active==true}"> <td>停止</td> </c:when>                     
           <c:otherwise> <td>开启</td> </c:otherwise>                    
        </c:choose>  
          
   </tr>  
  </c:forEach>  

以上转载自:http://summerli.iteye.com/blog/1683092

抱歉!评论已关闭.