0

I am getting the result set from the controller to the jsp page where I have a table.

I inserted all the data coming from resultset to the of that table.

The problem I am having is that data is coming in only one column. What I want to do is just limit the data to 5 in each column (5 in col 1, 5 in col 2, 5 in col3 of the same row).

Associated ID's:

AKR
AK
AKRBS
AKRB
AKBS
AKRB
AKRBS
AKRBSW
AK
AKRE

and so on.....

user1847801
  • 27
  • 1
  • 2
  • 5
  • What? Do you want 5 rows, or 5 columns? The former is what you asked, but this makes in real world no sense, the latter makes in real world more sense. Your "5 in each column" is interpretable as "5 cells in each column" and thus 5 rows. Note that the answers posted so far also assume 5 columns. – BalusC Mar 05 '13 at 18:12

2 Answers2

0

you should be able to add a counter and use

${ counter % 5 == 0 }

to trigger a <br> or whatever you're using to create a line break.

This is the MOD operator and it returns 0 when the count returned is a multiple of 5. Any non multiple of 5 would return a non-zero number.

Matt Busche
  • 14,216
  • 5
  • 36
  • 61
0

check this code

<table >
    <tr valign="top">
        <% int len=102;
            out.print("<td>");
            for(int i=0;i<len;i++){
                if(i%5==0 && i!=0 && i !=len)
                    out.print("</td><td>");
                out.print("item "+i+"<br>");

            }
            out.print("</td>");

        %>

    </tr>
</table>
Daniel Robertus
  • 1,100
  • 1
  • 11
  • 24
  • *Scriptlets* are [discouraged](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202) since a decade. – BalusC Mar 05 '13 at 18:13