当前位置: 代码迷 >> J2SE >> 关于使用struts标签 判断集合长度是否为0 的实现有关问题
  详细解决方案

关于使用struts标签 判断集合长度是否为0 的实现有关问题

热度:204   发布时间:2016-04-24 12:42:40.0
关于使用struts标签 判断集合长度是否为0 的实现问题
我struts标签用的不是很熟 
最近没事研究研究
我在实现列表页面的时候遇到了困难
业务是得到request中的persons集合(List)
然后判断如果persons的size()为0 就输出个<tr><td>无记录</td></tr>
如果不为零 再迭代
现在问题就处在struts标签的<logic:equal 上了
HTML code
 <logic:present name="persons" scope="request">    <bean:size id="len" name="persons" scope="request"/>    <h1>长度是:${len}</h1>    <logic:equal value="0" name="${len}">        1    <tr><td>暂无记录</td></tr>    </logic:equal>    <logic:notEqual value="0" name="${len}">        23        <logic:iterate id="person" name="persons" scope="request" indexId="oid">            <tr>              <td>${oid+1}</td>              <td>${person.name}</td>              <td>${person.loginName}</td>              <td>${person.age}</td>            </tr>        </logic:iterate>    </logic:notEqual>    34    </logic:present>    <logic:notPresent name="persons" scope="request">         <tr><td>暂无记录</td></tr>    </logic:notPresent>


<logic:equal value="0" name="${len}">
这个判断老不成功。。。 len确实是0  
我估计问题可能出在数据类型上了

struts标签不会这么难用吧 =。= 。。。我不想再用c:if了。。。
高手指点下我把 谢谢了

------解决方案--------------------
个人建议用jstl标签,好用
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

比如说有一个集合 list
得出它这个集合的长度

${fn:length(list)} 就OK了
------解决方案--------------------
<logic:equal value="0" name="len">
1
<tr><td>暂无记录</td></tr>
</logic:equal>
<logic:notEqual value="0" name="len">
23
<logic:iterate id="person" name="persons" scope="request" indexId="oid">
<tr>
<td>${oid+1}</td>
<td>${person.name}</td>
<td>${person.loginName}</td>
<td>${person.age}</td>
</tr>
</logic:iterate>
</logic:notEqual>

login标签接数据的时候不需要用到el标签
直接写变量名就可以了
  相关解决方案