tags:

views:

34

answers:

1

Hi, everyone,

I want to ask a question about the JSP. I writing the following code in the JSP page. However, when I set the <%= obj.getCounter()%> (use-defined method) to be the loop counter, I found that it does not work. Can anyone help me? Thank you.

The following is the code.

<%
private int loopTime = <%= obj.getCounter()%>;
%>

<% for(int i=0; i<loopTime; i++) { %>
<tr>
    <td><%= obj.getName() %></td>
    <td><%= obj.getAge() %></td>
</tr>
<%}%>
+4  A: 

You can't include one scriptlet inside another: what's the point?

<% int loopTime = obj.getCounter(); %>

Is this what you wanted? I'm asking because loopTime isn't the 'loop counter' in your code, it's loop upper boundary.

Nikita Rybak
@Nikita Rybak, thank you for your answer. It is a great help.
Questions