Domanda

I am writing a method in JSP which dump rows of a table:

<%!  
    void dumpRows(List<MyClass> obList){  
        int a = 10;  
        for(int i = 0; i<100; i++){  
%>  
   //lots of HTML code which uses the variables from the dumpRows method  
   <td> <%=a*i%> </td>  
<%  
        }//for loop ends  
    }//method ends  
%>  

but it is erroring out. There's something wrong with the JSP grammar. Please help me on how can I achieve that

È stato utile?

Soluzione 2

I think the problem is that you are mixing <%!, <% and <%=.
If you separate business logic and view it will be much easier and clear.
You can use JSTL tag <c:forEach> to output your html table.

Altri suggerimenti

<%!  
    void dumpRows(List<MyClass> obList){  
        int a = 10;  
        for(int i = 0; i<100; i++){  
%>  
   //lots of HTML code which uses the variables from the dumpRows method  
   <td> <%=a*i%> </td>                 //here problem
<%  
        }//for loop ends  
    }//method ends  
%>

write this way to print <%=a*i%>

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top