0

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

4

2 回答 2

2
<%!  
    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  
%>

这样写打印 <%=a*i%>

于 2013-08-22T11:05:24.263 回答
1

我认为问题在于您正在混合<%!<%并且<%=.
如果你将业务逻辑和视图分开,它会更容易和清晰。
您可以使用 JSTL 标签<c:forEach>来输出您的 html 表格。

于 2013-08-22T12:39:05.637 回答