我的 Spring 3.2 MVC 应用程序中有以下表单。控制器方法没有被调用。这是我的表格。
<form:form commandName="bulletin" method="post" value="/processBulletin">
<table>
<tr>
<td>Name:</td>
<td><form:input path="name" maxlength="30" /></td>
</tr>
<tr>
<td>Subject:</td>
<td><form:input path="subject" maxlength="50" /></td>
</tr>
<tr>
<td valign="top">Message:</td>
<td><form:textarea path="note" cols="70" rows="20" /></td>
</tr>
<tr>
<td><input type="button" value="Submit bulletin" name="submit" /></td>
<td> </td>
</tr>
</table>
</form:form>
这是我的控制器方法。
@RequestMapping(value = "/processBulletin", method = RequestMethod.POST)
@ModelAttribute("bulletin") Bulletin bulletin, Model model,
BindingResult result) {
final BindException errors = new BindException(bulletin, "bulletin");
bulletinValidator.validate(bulletin, errors);
if (errors.hasErrors()) {
return "redirect:/approvedBulletins";
} else {
try {
bulletin.setSubject(bulletin.getSubject().trim());
bulletin.setName(bulletin.getName().trim());
bulletin.setNote(bulletin.getNote().trim());
long now = System.currentTimeMillis();
Calendar date = Calendar.getInstance();
date.setTimeInMillis(now);
bulletin.setDay((date.get(Calendar.MONTH) + 1) + "/"
+ date.get(Calendar.DATE) + "/"
+ date.get(Calendar.YEAR));
bulletinDAO.writeBulletin(bulletin.getName(),
bulletin.getSubject(), bulletin.getDay(),
bulletin.getNote());
} catch (Exception e) {
System.out.println(e.getMessage());
return "FailurePage";
}
}
return "redirect:/approvedBulletins";
}