我在一个jsp页面上有两个表单。第一种形式不使用modelAttribute,第二种使用modelAttribute。问题是,如果我发布第一个不使用modelAttribute的表单,它会声明一个错误,我没有绑定modelAttribute。多个表单在一个jsp中
我在互联网上搜索寻找解决方案,但我找不到一个有用的。
changeAddress.jsp
<form method="post">
<input type="hidden" name="id" value="0" />
<input type="submit" name="exist" value="send to this address" />
</form>
<form:form method="post" modelAttribute="addressForm">
<form:input path="street" />
<input type="submit" name="add" value="send to this address" />
</form:form>
OrderController.java
@RequestMapping(value="changeAddress",method = RequestMethod.GET)
public ModelAndView showChangAddress(Model model)
{
model.addAttribute("addressForm", new AddressForm());
return new ModelAndView("body.changeaddress");
}
@RequestMapping(value="changeAddress", params="add", method = RequestMethod.POST)
public ModelAndView addChangAddress(@ModelAttribute("addressForm") @Valid AddressForm af, BindingResult result, Model model)
{
System.out.println("a");
return new ModelAndView("body.changeaddress");
}
@RequestMapping(value="changeAddress", params="exist", method = RequestMethod.POST)
public ModelAndView processChangAddress(@RequestParam(value="id") String id, Model model)
{
System.out.println("b");
return new ModelAndView("body.changeaddress");
}
大大appriciated的帮助:)
您正在使用哪个版本的Spring? – Lion
3.1.3发布版本 – Skyverian
您可以尝试使用document.forms [0] .submit仅提交第一个表单。 – prashanth