由于您已经在 onclick 中更改了表单操作 URL(这是一种非常糟糕的做法,但除此之外),为什么不同时添加行标识符呢?
<input type="submit" name="<%=t %>" value="edit" onclick="this.form.action='df1.jsp?flag=1&act=1&edit=<%=t%>';this.form.submit();" />
<input type="submit" name="<%=t %>" value="delete" onclick="this.form.action='df1.jsp?flag=1&act=1&delete=<%=t%>';this.form.submit();" />
这样你就可以这样做:
String edit = request.getParameter("edit");
if (edit != null) {
// Edit button of row "edit" was invoked. Do your job here.
}
String delete = request.getParameter("delete");
if (delete != null) {
// Delete button of row "delete" was invoked. Do your job here.
}
否则,您需要在按钮名称前加上一些固定标识符:
<input type="submit" name="edit_<%=t %>" value="edit" onclick="this.form.action='df1.jsp?flag=1&act=1';this.form.submit();" />
<input type="submit" name="delete_<%=t %>" value="delete" onclick="this.form.action='df1.jsp?flag=1&act=1';this.form.submit();" />
这样你就可以做到:
for (int t = 1; t < 10; t++) {
if (request.getParameter("edit_" + t) != null) {
// Edit button on index "t" was invoked. Do your job here.
break;
}
if (request.getParameter("delete_" + t) != null) {
// Delete button on index "t" was invoked. Do your job here.
break;
}
}
与具体问题无关,使用scriptlet 以这种方式编写 JSP<% %>
十年以来一直被认为是老派和糟糕的做法。另请参阅如何避免 JSP 文件中的 Java 代码?