Need to display an ArrayList of Java Bean properties in a JSP page using Expression Language (EL)

Here is a snippet of my Servlet code:

ArrayList personList = new ArrayList();
Person person1 = new Person();
person1.setName("Fred");
person1.setAddress("100 Main");
person1.setZipCode("90289");
personList.add(person1);

Person person2 = new Person();
person2.setName("Andy");
person2.setAddress("200 Main");
person2.setZipcode("90289");
personList.add(person2 );

request.setAttribute("persons", personList);
request.getRequestDispatcher("jsps/displayResults.jsp").forward(request, response);

________________________________________________________________________________________

In my displayResults.jsp I have the following code snippet:
<table>
       <c:forEach var="theperson" items="${persons}">
             <tr><td>${theperson.name}</td></tr>
             <tr><td>${theperson.address}</td></tr>
             <tr><td>${theperson.zipcode}></td></tr>
       </c:forEach>
</table>


If I use an ArrayList of Strings I can get it to print out the strings in the ArrayList.  But I can't get it to work with an ArrayList of "Person" beans.
gdkinney_2Asked:
Who is Participating?
 
ManishLeadCommented:
In scriptlet , are you able to access these object?
0
 
KuldeepchaturvediCommented:
whats the error you are getting? by the look of it, it should work.
0
 
Pramod KumarCommented:
Could you share your bean source code. Just to ensure that the getters are available there.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.