user1472018
user1472018

Reputation: 31

HTML table does not display value from ArrayList

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

Answers (2)

AG_
AG_

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

Neha Shettar
Neha Shettar

Reputation: 713

Try <%= arrColHead.get(i) %> OR out.println(arrColHead.get(i));

Upvotes: 2

Related Questions