我在一個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