【发布时间】:2011-10-29 10:31:20
【问题描述】:
我有一个 jsp,它向我显示了来自基地的学生列表。对于每个学生,我想要 2 个按钮 - 编辑和删除。单击编辑时,请求应重定向到我的 servlet 控制器,并打开一个用于编辑所选学生数据的新 jsp。单击删除时,所选学生的删除请求将发送到控制器。现在看起来像这样:
<%@page import="socnet2.Student"%>
<!-- class Student emulates real student -->
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<jsp:useBean class="socnet2.DAO" id="dao" scope="request"></jsp:useBean>
<p><b>List of all students:</b></p>
<form action="/JSP1/Controler" method="POST">
<jsp:scriptlet>
for (Student s : dao.getAllStudents()) {
</jsp:scriptlet>
<p> <jsp:expression> s.getName() + " " + s.getSurname()</jsp:expression></p>
<input type="submit" name="Edit" value="Edit" />
<input type="submit" name="Delete" value ="Delete"/>
<jsp:scriptlet>
}
</jsp:scriptlet>
</form>
</body>
问题是我无法弄清楚如何将我的学生与按钮连接起来,以便在将请求发送到控制器时知道单击了哪个按钮以及选择了哪个学生。我知道我需要每个学生的唯一 ID,但不知道如何创建它...
【问题讨论】: