Skip to content

JSP page to display ArrayList elements using for loop

An Example which explains how to display ArrayList elements using for loop.


//ArrayList which contains list of student details

<%
ArrayList <studentBean> arl=(ArrayList) request.getAttribute("studentBean");
%>

<table>
<tr>
<th>STUDENTID </th>
<th>FIRST NAME </th>
<th>LASTNAME</th>
<th>CLASS</th>

</tr>

<% try
{
for(int i=0;i<arl.size();i++)
{

<tr>
<td><%=arl.get(i).getstudentID()%></td>
<td><%=arl.get(i).getstudentFname()%></td>
<td><%=arl.get(i).getstudentLname()%></td>
<td><%=arl.get(i).getClass1()%></td>
</tr>
<%}
}
catch(Exception e)
{
System.out.println("Exception");
}
%>
</table>
.