Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot create iterator for this...ArrayList()...  RSS feed

Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help please!

Process flow
Index.jsp is supposed to execute the getCustomer() method in customerAction class. The customerAction is supposed to put a customers ArrayList object in the request scope. the customer.jsp screen is supposed to iterate through the customer ArrayList object that was placed in the request scope and display the data in their respective fields.

My objective is to display the data brought back from the database.

When I debugged CustomerAction class with these lines of code:

Iterator i = customers.iterator();
while( i.hasNext() ){
System.out.println( "((CustomerBean) " + ((CustomerBean) );

, I got the following out from the Arraylist object that is placed the the request scope:

((CustomerBean) OLA
((CustomerBean) OLATEST
((CustomerBean) SAUD

Please tell me the cause of the error and how to work round it. In any case, is there a more efficient way of achieving my objective?


Ola Oke
When I execute/run index.jsp screen I get the error below:

org.apache.jasper.JasperException: Cannot create iterator for this collection
at org.apache.jasper.servlet.JspServletWrapper.service(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationDispatcher.invoke(
at org.apache.catalina.core.ApplicationDispatcher.doForward(
at org.apache.catalina.core.ApplicationDispatcher.forward(
at org.apache.struts.action.RequestProcessor.doForward(
at org.apache.struts.action.RequestProcessor.processForwardConfig(


index.jsp (This is the JSP the processing that leads to the error):
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<jsp:forward page="/"/>

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<html:form action="/customer"
type="com.cargo.gen.CustomerForm" >
<logic:iterate id="customer" name="customers">
<tr align="left">
<td><bean:write name="customer" property="customerNo"/>:</td>
<td><bean:write name="customer" property="firstName"/>:</td>

struts-config.xml file:
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"


<!-- ==================================== Data Source Configuration -->

<data-source type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
<set-property property="url" value="jdbc:mysql://localhost/cargo" />
<set-property property="username" value="ola" />
<set-property property="password" value="ola" />

<!-- ======================================== Form Bean Definitions -->

<form-bean name="customerForm" type="com.cargo.gen.CustomerForm"/>

<forward name="cust" path="/customer"/>

<action path="/customer"
<forward name="success" path="/jsp/customer.jsp"/>
<forward name="failure" path="/jsp/failure.jsp"/>

<message-resources parameter="com.cargo.resources.application"/>


Action Class:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import java.util.ArrayList;
import java.util.Iterator;

public class CustomerAction extends DispatchAction {

public ActionForward getCustomer(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {

DbInterface dbInterface = new DbInterface();
ArrayList customers = dbInterface.getCustomer( getDataSource(request) );
request.setAttribute("customers", "customers");

Iterator i = customers.iterator();
while( i.hasNext() ){
System.out.println( "((CustomerBean) " + ((CustomerBean) );

return mapping.findForward("success");


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!