我在一个jsp页面上有两种形式.第一种形式不使用modelAttribute,第二种形式使用modelAttribute.问题是,如果我发布不使用modelAttribute的第一个表单,则会声明我没有绑定modelAttribute的错误.
我已经在互联网上搜索了解决方案,但是找不到有用的解决方案.
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");
}
恳求帮助:)
最佳答案
关于< form>的spring形式标签库documentation .标签:
This tag renders an HTML ‘form’ tag and exposes a binding path to inner tags for binding. It puts the command object in the PageContext so that the command object can be accessed by inner tags.
我认为您从Spring< form>起就不需要任何东西了.以您的第一种形式标记.因此,您可以使用简单的html表单代替:
<form method="post" action="...">
<input type="hidden" name="id" value="0" />
<input type="submit" name="exist" value="send to this address" />
<form>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。