0

I have a quick question on iterating over an array list from a class file onto jsp file.

Snippet from a class file:

ArrayList al = new ArrayList();
public ArrayList getStatus() {
   Object o;
   this.Status = al;  //contents of the array list  
   return Status;
}

Below is a snippet from the jsp file:

<jsp:useBean id="mybean" class="org.mypackage.process" scope="session" >



<jsp:setProperty name="mybean" property="input" value="hello" />



</jsp:useBean>



<jsp:getProperty name="mybean" property="status" />

When I run above, I get the arraylist as a bunch of string separated by commas. I need help in generating a table with the output from the array list. Can the array list be generated using forEach so that I can create tables.

I am not using any frameworks. I can run jstl tags on jsp.

Thanks in advance.

Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71
user2357036
  • 13
  • 1
  • 1
  • 7

1 Answers1

1

Use the forEach loop of JSTL. You can check the SO answer here as well.

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<table>
  <th>Header1</th>
  <th>Header2</th>
  <c:forEach items="${mybean.status}" var="element">
    <tr>
      <td><c:out value="${element.attribute1}" /><td>
      <td><c:out value="${element.attribute2}" /><td>
    </tr>
  </c:forEach>
</table>
Community
  • 1
  • 1
AllTooSir
  • 48,828
  • 16
  • 130
  • 164
  • Thanks Noob. It worked. – user2357036 May 07 '13 at 14:12
  • Noob - Can you please elaborate on the attributes? Can you please include an example on how I can create an array list containing multiple columns(attribute1,attribute2, etc) on the class file to display on a jsp file? – user2357036 May 08 '13 at 06:14