我有以下代码
JSP
<tbody>
<c:forEach var="defect" items="${defects}">
<tr>
<td>${defect.name}</td>
<td>${defect.description}</td>
<td>${defect.summary}</td>
<td>${defect.priority}</td>
<td>${defect.originator.name}</td>
<td>${defect.assignee.name}</td>
<td>
<form action="AllOpenDefects?defectId=${defect.id}" method="get">
<input type="submit" value="Update" />
</form>
</td>
</tr>
</c:forEach>
</tbody>
Servlet(在doGet方法中)
System.out.println((String) request.getParameter("defectId")); // It is printing null
并且还没有在URL中添加
defectId
...我的代码有问题吗?编辑:URL是
http://localhost:8080/BugManagemetSystem/AllOpenDefects
,但它应该像http://localhost:8080/BugManagemetSystem/AllOpenDefects?defectId=2
最佳答案
看来您的浏览器在?...
属性中的action="..."
之后清除了参数。在这种情况下,请尝试通过<input type="hidden" .../>
<form action="AllOpenDefects" method="get">
<input type="hidden" name="defectId" value="${defect.id}"/>
<input type="submit" value="Update" />
</form>
这样,表单应将它们以
?defectId
= value of ${defect.id}
的形式添加到URL。