Reputation: 31
I want to display a table by retrieving values from an Arraylist in my JSP. This is the table section of the code from the JSP
<p>
<table id="myTable">
<tr class="header">
<%
ArrayList arrColHead = new ArrayList();
arrColHead.add("Col Head 1");
rrColHead.add("Col Head 2");
for(int i=0; i < arrColHead.size(); i++)
{
%>
<th style="width:10%">
<%
arrColHead.get(i);
%>
</th>
<%
}
%>
</tr>
</table>
This does not display "Col Head 1" and "Col Head 2". What could possibly be wrong?
However, if I try to hard code the values, it shows the table properly.
for(int i=0; i < arrColHead.size(); i++)
{
%>
<th style="width:10%">
Col Head 1
</th>
<%
}
I am new to J2EE programming. So any help here is appreciated
Upvotes: 0
Views: 197
Reputation: 54
Check it might be simple issue.
ArrayList arrColHead = new ArrayList();
arrColHead.add("Col Head 1");
rrColHead.add("Col Head 2");
in second add it should be
arrColHead.add("Col Head 2");
not
rrColHead.add("Col Head 2");
Just check.
Upvotes: 0
Reputation: 713
Try <%= arrColHead.get(i) %>
OR out.println(arrColHead.get(i));
Upvotes: 2