2013-01-03 22 views
3

我在一个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的帮助:)

+0

您正在使用哪个版本的Spring? – Lion

+0

3.1.3发布版本 – Skyverian

+0

您可以尝试使用document.forms [0] .submit仅提交第一个表单。 – prashanth

回答

3

弹簧形式的taglib documentation有关<form>标签:

该标记呈现HTML“表单”标记并公开绑定路径以通过内部标记进行绑定。它将命令对象放在PageContext中,以便命令对象可以被内部标签访问。

我认为你不需要任何东西从你的第一种形式的春天<form>标签。因此,您可以使用简单的html表单代替:

<form method="post" action="..."> 
    <input type="hidden" name="id" value="0" /> 
    <input type="submit" name="exist" value="send to this address" /> 
<form> 
+0

我已经这样做了,但它使我陷入了同样的错误 – Skyverian

相关问题