所以这是我在 jsp 文件中的自定义标签:
<myTags:myTag name="John">
Value of k: ${valueOfK}
<br />
</myTags:myTag>
我拥有的标签处理程序类:
@Override
public void doTag() throws JspException, IOException {
getJspContext().getOut().print("<table>");
for (int i = 0; i < 10; i++) {
getJspContext().getOut().print("<tr>");
for (int k = 0; k < i; k++) {
getJspContext().getOut().print("<td>" + name + "</td>");
getJspContext().setAttribute("valueOfK",k);
}
getJspBody().invoke(null);
getJspContext().getOut().print("</tr>");
}
getJspContext().getOut().print("</table>");
}
所以输出将是:
Value of k:
Value of k: 0
Value of k: 1
Value of k: 2
Value of k: 3
Value of k: 4
Value of k: 5
Value of k: 6
Value of k: 7
Value of k: 8
John
John John
John John John
John John John John
John John John John John
John John John John John John
John John John John John John John
John John John John John John John John
John John John John John John John John John
但我想要实现的是:
John Value of k: 1
John John Value of k: 2
ETC...
为什么先打印所有的k值,然后再构造表?