我在JSP中编写了一个转储表行的方法:
<%!
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
%>
但它错了。 JSP语法有问题。请帮助我如何实现
答案 0 :(得分: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
%>
以这种方式打印&lt;%= a * i%&gt;
答案 1 :(得分:1)
我认为问题在于您混合了<%!
,<%
和<%=
。
如果您将业务逻辑分开并查看它将更加容易和清晰
您可以使用JSTL标记<c:forEach>
输出您的html表。