Java-在一个jsp中使用多种形式

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

相关文章

这篇文章主要介绍了spring的事务传播属性REQUIRED_NESTED的原...
今天小编给大家分享的是一文解析spring中事务的传播机制,相...
这篇文章主要介绍了SpringCloudAlibaba和SpringCloud有什么区...
本篇文章和大家了解一下SpringCloud整合XXL-Job的几个步骤。...
本篇文章和大家了解一下Spring延迟初始化会遇到什么问题。有...
这篇文章主要介绍了怎么使用Spring提供的不同缓存注解实现缓...