我有一个带有 2 个参数的 Spring 3 MVC 表单,我试图将其发送到我的控制器方法,但出现 404 错误。这个问题的转折是表单有 2 个提交按钮,单击的提交按钮决定了其中一个参数的值。这是我的表格。
<form:form action="/approve/${bulletin.id}" method="post">
<table>
<tr>
<td colspan="2"><b>From:</b> <c:out value="${bulletin.name}" /></td>
</tr>
<tr>
<td colspan="2"><b>Subject:</b> <c:out
value="${bulletin.subject}" /></td>
</tr>
<tr>
<td colspan="2"><b>Date:</b> <c:out value="${bulletin.date}" />
<br></td>
</tr>
<tr>
<td colspan="2"><t:notePrint note="${bulletin.note}" /> <input
type="hidden" name="id" value="${bulletin.id}" /></td>
</tr>
<tr>
<td><input type="submit" name="approve" value="Approve" /></td>
<td><input type="submit" name="deny" value="Deny" /></td>
</tr>
</table>
<br />
</form:form>
这是我的控制器表单。
@RequestMapping(value = "/approve/{id}", method = RequestMethod.POST)
public String approveBulletin(@RequestParam int id,
@RequestParam(required = false, value = "approve") String approve,
@RequestParam(required = false, value = "deny") String deny, Model model) {
try {
if (approve.equalsIgnoreCase("approve")) {
bulletinDAO.approveBulletin(id);
model.addAttribute("approval",
"Your bulletin has been approved.");
}
if (deny.equalsIgnoreCase("deny")) {
bulletinDAO.denyBulletin(id);
model.addAttribute("approval", "Your bulletin has been denied.");
}
List<Bulletin> bulletins = bulletinDAO.getApprovedBulletins();
model.addAttribute("bulletins", bulletins);
} catch (Exception e) {
System.out.println(e.getMessage());
return "FailurePage";
}
return "ApproveBulletin";
}