jsp - Print an array in a table using JSTL -


this example of array have :

string[] dataname = {"gene name","promoter name","source","year","author"}; string[] proteinlist = {"protein01","aox","yarrowia","2006","john doe","protein02","pgap","homo sapiens","1997","john smith"}; 

the actual array can contain 30 values.

the display of data should in table :

| gene name  | promoter name  | source       | year  | author    | | protein01  | aox            | yarrowia     | 2006  | john doe  | | protein02  | pgap           | homo sapiens | 1997  | john smith| 

but result :

| gene name  | promoter name  | source       | year  | author    | | protein01  | aox            | yarrowia     | 2006  | john doe  | protein02  | pgap           | homo sapiens | 1997  | john smith| 

in jstl, how have written :

<tr>     <c:foreach items="${dataname}" var="namedata">     <td class="body" valign="top" align="left"><b><c:out value="${namedata}"/></b></td>     </c:foreach> </tr>   <tr>     <c:foreach items="${proteinlist}" var="result">     <td class="datafield" valign="top"><c:out value="${result}"/></td>     </c:foreach> </tr> 

is there ways can use loop proteinlist[] loop proteinlist[5] in new row?

thank help.

try this, insert tr tags when index reaches 5th element:

<tr>     <c:foreach items="${dataname}" var="namedata">     <td class="body" valign="top" align="left"><b><c:out value="${namedata}"/></b></td>     </c:foreach> </tr>  <c:foreach items="${proteinlist}" var="result" varstatus="proteincount">   <c:if test=((proteincount.count+1)/5)=0>     <tr>   </c:if>         <td class="datafield" valign="top"><c:out value="${result}"/></td>    <c:if test=((proteincount.count+1)/5)=0>     </tr>   </c:if> </c:foreach> 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -