javax.servlet.jsp.JspException:找不到集合

时间:2017-06-06 05:13:38

标签: java arrays jsp

This is my arraylist for index 17

在此代码中可能有数据列表或可能没有。有记录时数据会发送。没有处理没有记录

Java代码:

 //To avoid arrayindexoutofbound exception length checked
    if (resultList.length >17) {
    statisticsDetails.setqNames(resultList[17]);
    //System.out.println(resultList[17]);
    String[]  qName=resultList[17].split("\\^");


   List<StatisticsDetails> statisticsDetailsList = new ArrayList<StatisticsDetails>();
    for (String queueName:qName  ){
    StatisticsDetails  details = new StatisticsDetails();
    String[] splitQueues = queueName.split("=");
    details.setqKey(splitQueues[0]);
    details.setqCount(splitQueues[1]);
    statisticsDetailsList.add(details);
    }
    statisticsDetails.setqNamesList(statisticsDetailsList);
    }

Jsp代码:

<logic:iterate id="iteratorId" name="statistics.statisticsDetails" property="qNamesList">
<tr>
<td class="col-sm-6 col-md-6 col-lg-6"><bean:write name="iteratorId" property="qKey" /></td>
<td class="col-sm-6 col-md-6 col-lg-6"><bean:write name="iteratorId" property="qCount" /></td>
</tr>
</logic:iterate>

如何在没有找到数据的情况下避免数组绑定错误和JSP处理

2 个答案:

答案 0 :(得分:0)

  1. 使用JSTL (Do not forget to import the tag library)使用空检查:  导入核心库: <%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> 然后使用:

    <c:if test="${not empty statistics.statisticsDetails}"> //keep your code here to iterate the list </c:if>

  2. 或使用:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 然后:

    <c:if test="${fn:length(statistics.statisticsDetails) > 0}"> //keep your code here to iterate the list </c:if>

答案 1 :(得分:0)

请在struts-config.xml中检查所有映射是否正确。就我而言,我发现表单的类型不正确,然后出现了错误。类型表示表格的包装名称。在标签中。

相关问题