简体   繁体   中英

javax.servlet.jsp.JspException: No collection found

This is my arraylist for index 17

In this code may have data list or may not. Data is dispay when there are records. Not handled for no records

Java code:

 //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 code:

<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>

how to avoid arraybound error and JSP to handle when no data found

  1. Use a null check using JSTL (Do not forget to import the tag library) : import core library: <%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> and then use:

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

  2. Or use:

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

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

Please check all mapping is correct or not in the struts-config.xml. In my case, i found incorrect type was mentioned for form and then it was giving the error. Type means package name for the form. in tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM